排球发送POST参数总是空的

时间:2014-08-23 18:27:27

标签: android json post android-volley

我的Android客户端上有这个代码:

    int method = Request.Method.POST;

    JSONObject params = new JSONObject();
    try {
        params.put("data", userJson);
    } catch (JSONException e) {
        LogSystem.e(tag, "JsonObject - Params", e);
    }

    String url = "http://appdorneira.com:8001/rest/test";
    // URL_USER_INFO;// + "?data='" + userJson + "'";
    LogSystem.d(tag, url);

    JsonObjectRequest request = new JsonObjectRequest(method, url, params,
            resOk, errorListener);
    queue.add(request);

但在我的服务器中总是有类似的东西:

  

GET:QueryDict:{},POST:QueryDict:{}

我没有看到错误。我做错了什么?

2 个答案:

答案 0 :(得分:2)

现在,我使用的是VolleyPlus(https://github.com/DWorkS/VolleyPlus),此代码适用于我:

    int method = Request.Method.POST;

    String url = URL_USER_INFO;
    LogSystem.d(tag, url);

    StringRequest request = new StringRequest(method, url, resOk,
            errorListener) {

        protected Map<String, String> getParams()
                throws com.android.volley.error.AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("data", userJson);
            return params;
        };
    };

    queue.add(request);

答案 1 :(得分:1)

调试并跟踪连接以查看实际发送的内容。服务器上也可能出现问题。