英文:
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,
"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);
}
专注分享java语言的经验与见解,让所有开发者获益!
评论