Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓截击给我400个错误代码(错误请求)_Android_Json_Android Volley_Postman_Bad Request - Fatal编程技术网

Android 安卓截击给我400个错误代码(错误请求)

Android 安卓截击给我400个错误代码(错误请求),android,json,android-volley,postman,bad-request,Android,Json,Android Volley,Postman,Bad Request,我正试图使用Volley向我的应用程序发出POST请求,但它显示 E/Volley﹕ [9988] BasicNetwork.performRequest: Unexpected response code 400 for http://test_url/SendMessage 但它在《邮递员》中运行良好 邮差快照: public JSONObject getJsonObject() { Map<String, Object> postParam = new Has

我正试图使用
Volley
向我的应用程序发出POST请求,但它显示

E/Volley﹕ [9988] BasicNetwork.performRequest: Unexpected response code 400 for http://test_url/SendMessage
但它在《邮递员》中运行良好

邮差快照:

public JSONObject getJsonObject() {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("Recipients", new String[]{authorId + ":I"});
        postParam.put("Subject", etSubject.getText().toString());
        postParam.put("Text", etMessage.getText().toString());
        postParam.put("MessageState", "N");
        postParam.put("ParentId", "");
        postParam.put("PrivateMessageGuid", GUID);
        Log.i("JSON Parameter ===", Utils.getRequestJSONObject(postParam).toString());
        return Utils.getRequestJSONObject(postParam);
    }
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,
            Constants.ReplyMessageUrl, getJsonObject(),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Toast.makeText(getApplicationContext(),
                            "Message Send", Toast.LENGTH_SHORT).show();

                }
            }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(),
                    getResources().getString(R.string.try_again), Toast.LENGTH_SHORT).show();
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<>();
            headers.put("Authorization", mApp.getTokenType() + " " + mApp.getAccessToken());
            headers.put("Content-Type", "application/json");
            headers.put("Accept", "application/json");
            return headers;
        }
    };

    RequestQueue mRequestQueue = mApp.getRequestQueue();
    mRequestQueue.add(jsonReq);

这是我的代码:

public JSONObject getJsonObject() {
        Map<String, Object> postParam = new HashMap<>();
        postParam.put("Recipients", new String[]{authorId + ":I"});
        postParam.put("Subject", etSubject.getText().toString());
        postParam.put("Text", etMessage.getText().toString());
        postParam.put("MessageState", "N");
        postParam.put("ParentId", "");
        postParam.put("PrivateMessageGuid", GUID);
        Log.i("JSON Parameter ===", Utils.getRequestJSONObject(postParam).toString());
        return Utils.getRequestJSONObject(postParam);
    }
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,
            Constants.ReplyMessageUrl, getJsonObject(),
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Toast.makeText(getApplicationContext(),
                            "Message Send", Toast.LENGTH_SHORT).show();

                }
            }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getApplicationContext(),
                    getResources().getString(R.string.try_again), Toast.LENGTH_SHORT).show();
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            HashMap<String, String> headers = new HashMap<>();
            headers.put("Authorization", mApp.getTokenType() + " " + mApp.getAccessToken());
            headers.put("Content-Type", "application/json");
            headers.put("Accept", "application/json");
            return headers;
        }
    };

    RequestQueue mRequestQueue = mApp.getRequestQueue();
    mRequestQueue.add(jsonReq);

请帮我找到解决办法。谢谢。

安装wireshark并比较其中的两个请求,以查看实时流量的差异。+最好使用GSON,并根据getJsonObject()中的内容完成类。

似乎是@random的重复question@Viks你有什么办法吗?我也有同样的办法