【问题标题】:Volley Send POST Params Always EmptyVolley 发送 POST 参数始终为空
【发布时间】:2014-08-23 18:27:27
【问题描述】:

我的 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: {}

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

【问题讨论】:

标签: android json post android-volley


【解决方案1】:

现在,我正在使用 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);

【讨论】:

    【解决方案2】:

    调试并跟踪连接以查看真正发送的内容。服务器也可能有问题。

    【讨论】:

      猜你喜欢
      • 2014-09-15
      • 2019-02-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-18
      • 2016-11-22
      • 2017-08-09
      相关资源
      最近更新 更多