我想通过REST连接到服务器,但我有Volley 400错误; 我尝试了几乎所有我能找到的东西,但没有; 如果能帮助我,我将不胜感激! 这是我的代码:
private void volleyCall(String phone, String token) {
RequestQueue queue = Volley.newRequestQueue(this);
String URL = "http://1*4.***.**.1*1/login/register-phone";
Map<String, String> jsonParams = new HashMap<>();
jsonParams.put("phone", phone);
jsonParams.put("admin_token", token);
Log.i("log1", "Json:" + new JSONObject(jsonParams));
JsonObjectRequest postRequest = new
JsonObjectRequest(Request.Method.POST, URL,new JSONObject(jsonParams),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("log2", "Json" + response);
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// Handle Error
Log.i("log3", "Error: " + error
+ "\nStatus Code " +
error.networkResponse.statusCode
+ "\nResponse Data " +
error.networkResponse.data
+ "\nCause " + error.getCause()
+ "\nmessage" + 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");
Log.i("log4",headers.toString());
return headers;
}
@Override
public String getBodyContentType() {
return "application/json";
}
};
queue.add(postRequest);
}
有人告诉我应该删除这个表单标题:(我也试过,但同样的错误!)
headers.put("Content-Type", "application/json; charset=utf-8");