Android Volley выдает мне код ошибки 400 (неверный запрос)

Я пытаюсь отправить запрос POST в свое приложение, используя Volley, но оно говорит

E/Volley﹕ [9988] BasicNetwork.performRequest: Unexpected response code 400 for http://test_url/SendMessage

Но он отлично работал в PostMan.

Снимок почтальона:

введите здесь описание изображения

Вот мой код:

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);
    }

Параметр JSON === {"PrivateMessageGuid":"ac74df70-77d8-4281-a723-5c3c65f4d212", "Text":"hello test", "MessageState":"N","Subject":"Re: Hello Sundar","Recipients":["311:I"],"ParentId":""}

Основной код:

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);

Пожалуйста, помогите мне получить решение. Спасибо.


person Vikash Parajuli    schedule 22.06.2015    source источник
comment
кажется дубликатом stackoverflow.com/questions/21739276 /   -  person random    schedule 22.06.2015
comment
@random я видел этот вопрос   -  person Vikash Parajuli    schedule 22.06.2015
comment
@ Викс, у тебя есть какие-нибудь решения, я тоже получаю то же самое?   -  person Mohan    schedule 04.11.2015


Ответы (1)


Установите wireshark и сравните в нем оба запроса, чтобы увидеть разницу в живом трафике. + Предпочтительно использовать GSON с классом, созданным на основе того, что находится в getJsonObject()

person maxxxo    schedule 22.06.2015