【问题标题】:Volley post method return response code 500Volley post方法返回响应码500
【发布时间】:2015-06-24 09:42:51
【问题描述】:

使用 volley 时总是得到以下错误响应

06-24 15:06:59.244: E/Volley(12869): [2311] BasicNetwork.performRequest: Unexpected response code 500 for http://My_API

我的 Volley 调用代码

String sSignupUrl = STController.getInstance()
                .getResourceManager(LoginActivity.this)
                .getServerPropertyValue(URLConstants.API_LOGIN);
JSONObject params = new JSONObject();
        try {
            params.put("username", "usernam");
            params.put("passwd", "password");
        } catch (JSONException e) {
            e.printStackTrace();
        }
        JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST,
                sSignupUrl, params, new Response.Listener<JSONObject>() {

                    @Override
                    public void onResponse(JSONObject response) {
                        LogUtil.d("TAG" + response.toString());
                    }
                }, new Response.ErrorListener() {

                    @Override
                    public void onErrorResponse(VolleyError error) {
                        VolleyLog.d("TAG", "Error: " + error.getMessage());
                    }
                }) {

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> headers = new HashMap<String, String>();
                headers.put("Content-Type", "application/json; charset=utf-8");
                return headers;
            }

        };

        // Adding request to request queue
        AppController.getInstance().addToRequestQueue(jsonObjReq);

使用 URLConnection 管理器时我可以成功获得响应,但无法找到错误,我通过谷歌搜索但没有得到正确的解决方案,欢迎所有答案 提前致谢

【问题讨论】:

标签: android web-services android-volley


【解决方案1】:

我确实有同样的情况。我做错的是我将getHeaders() 包含在错误的JsonObjectRequest(i.e. with a wrong url) 中。但我在我的情况下使用了自定义标题。检查您的网址。它可能不是正确的。它可能不接受此标头。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多