相关疑难解决方法(0)

Volley JsonObjectRequest发布请求无效

我正在使用android Volley提出请求.所以我使用这段代码.我不明白一件事.我检查我的服务器,params始终为null.我认为getParams()不起作用.我该怎么做才能解决这个问题.

 RequestQueue queue = MyVolley.getRequestQueue();
        JsonObjectRequest jsObjRequest = new JsonObjectRequest(Request.Method.POST,SPHERE_URL,null,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response) {
                        System.out.println(response);
                        hideProgressDialog();
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                      hideProgressDialog();
                    }
                }) {
            protected Map<String, String> getParams() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();
                params.put("id","1");
                params.put("name", "myname");
                return params;
            };
        };
        queue.add(jsObjRequest);
Run Code Online (Sandbox Code Playgroud)

android android-volley

77
推荐指数
3
解决办法
14万
查看次数

Volley JsonObjectRequest Post参数不再有效

我正在尝试在Volley JsonObjectRequest中发送POST参数.最初,通过遵循官方代码所说的传递包含JsonObjectRequest的构造函数中的参数的JSONObject来为我工作.然后它突然停止工作,我没有对以前工作的代码进行任何更改.服务器不再识别正在发送任何POST参数.这是我的代码:

RequestQueue queue = Volley.newRequestQueue(this);
String url ="http://myserveraddress";

// POST parameters
Map<String, String> params = new HashMap<String, String>();
params.put("tag", "test");

JSONObject jsonObj = new JSONObject(params);

// Request a json response from the provided URL
JsonObjectRequest jsonObjRequest = new JsonObjectRequest
        (Request.Method.POST, url, jsonObj, new Response.Listener<JSONObject>()
        {
            @Override
            public void onResponse(JSONObject response)
            {
                Toast.makeText(getApplicationContext(), response.toString(), Toast.LENGTH_SHORT).show();
            }
        },
        new Response.ErrorListener()
        {
            @Override
            public void onErrorResponse(VolleyError error)
            {
                Toast.makeText(getApplicationContext(), error.toString(), Toast.LENGTH_SHORT).show();
            }
        });

// Add the request to …
Run Code Online (Sandbox Code Playgroud)

post android android-volley jsonobject

32
推荐指数
4
解决办法
7万
查看次数

标签 统计

android ×2

android-volley ×2

jsonobject ×1

post ×1