且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何发送与排球的数据POST请求?

更新时间:2023-01-03 13:32:02

  

要发送参数要求的身体,你需要重写或者    getParams()方法 getBody()的请求类的方法

来源:异步HTTP请求的Andr​​oid使用凌空

This is my android code

           JSONObject params = new JSONObject();
           params.put("username","rajesh@gmail.com");
           params.put("password","hellothere");

           JsonObjectRequest loginRequest = new JsonObjectRequest(
                    Request.Method.POST,
                    "http://192.168.2.67/tmp/test.php",
                    params,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject jsonObject) {
                        Log.d("","");

                        }
                    },
                    new Response.ErrorListener() {
                        @Override
                        public void onErrorResponse(VolleyError volleyError) {
                        Log.d("","");
                        }
                    });


            requestQueue.add(loginRequest);

The server code in php

            <?php
               $usr = $_REQUEST['username'];
                $pwd = $_REQUEST['password'];
                $resp[$usr]=$pwd;
                echo json_encode($resp);
               ?>

the response i'm getting is {"":null}

I tried with apache http cleint and it worked prferectly is there any way i can do this with volley?

To send parameters in request body you need to override either getParams() or getBody() method of the request classes

Source: Asynchronous HTTP Requests in Android Using Volley