27
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VolleyのPOST

Last updated at Posted at 2014-10-05

###下準備
・Volleyを取り込む
・PermissionでINTERNETを許可

###コード

MyActivity.java
public class MyActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_my);

        //queue
        RequestQueue queue = Volley.newRequestQueue(this);

        //url
        final String url = "http://www.bluecode.jp/test/res.php";

        //Request
        StringRequest postRequest = new StringRequest(Request.Method.POST,url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String s) {
                        Log.v("tama","RESPONSE=" + s);
                    }
                },
                new Response.ErrorListener(){
                    @Override
                    public void onErrorResponse(VolleyError error){
                        //error
                    }
                }){
                    @Override
                    protected Map<String,String> getParams(){
                        Map<String,String> params = new HashMap<String,String>();
                            params.put("name","hoge");
                            params.put("age","44");
                        return params;
                    }
        };

        queue.add(postRequest);
    }

こんな感じ。
###参考
ここシンプルな書き方
ここ分けた書き方

27
27
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
27

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?