BasicNetwork.performRequest: 意外的响应码 400,用于 https://fcm.googleapis.com/fcm/send

huangapple 未分类评论53阅读模式
英文:

BasicNetwork.performRequest: Unexpected response code 400 for https://fcm.googleapis.com/fcm/send

问题

> E/Volley: [7259] BasicNetwork.performRequest: 意外的响应代码 400,用于 https://fcm.googleapis.com/fcm/send

当我点击一个按钮时,会发送上述错误消息。我在我的手机上测试过。

我认为问题在下面的代码中,但我找不到它。

请帮我解决这个问题。

public void sendData(JSONObject requestData, final SendResponseListener listener) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST,
            "https://fcm.googleapis.com/fcm/send", requestData,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    listener.onRequestCompleted();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onRequestWithError(error);
        }
    }) {
        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            return params;
        }

        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> headers = new HashMap<String, String>();
            headers.put("Authorization", "key=(API key)");
            return headers;
        }

        @Override
        public String getBodyContentType() {
            return "application/json";
        }
    };

    request.setShouldCache(false);
    listener.onRequestStarted();
    queue.add(request);
}
英文:

> E/Volley: [7259] BasicNetwork.performRequest: Unexpected response code
> 400 for https://fcm.googleapis.com/fcm/send

When I press a button, it's sending above error message.
I tested it on my phone.

I think the problem is in code below,
but I couldn't find it.

Please help me to solve this problem.

public void sendData(JSONObject requestData, final SendResponseListener listener) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST,
            &quot;https://fcm.googleapis.com/fcm/send&quot;, requestData,
            new Response.Listener&lt;JSONObject&gt;() {
                @Override
                public void onResponse(JSONObject response) {
                    listener.onRequestCompleted();
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onRequestWithError(error);
        }
    }) {
        @Override
        protected Map&lt;String, String&gt; getParams() throws AuthFailureError {
            Map&lt;String, String&gt; params = new HashMap&lt;String, String&gt;();
            return params;
        }

        @Override
        public Map&lt;String, String&gt; getHeaders() throws AuthFailureError {
            Map&lt;String, String&gt; headers = new HashMap&lt;String, String&gt;();
            headers.put(&quot;Authorization&quot;, &quot;key=(API key)&quot;);
            return headers;
        }

        @Override
        public String getBodyContentType() {
            return &quot;application/json&quot;;
        }
    };

    request.setShouldCache(false);
    listener.onRequestStarted();
    queue.add(request);
}

huangapple
  • 本文由 发表于 2020年4月6日 22:16:57
  • 转载请务必保留本文链接:https://java.coder-hub.com/61061895.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定