【发布时间】:2016-03-21 15:48:17
【问题描述】:
我使用下面的代码来获取 Volley 请求并获取 json:
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,
service_address , null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
VolleyLog.d(TAG, "Response: " + response.toString());
if (response != null) {
parseJsonFeed(response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String, String>();
params.put("username", username);
params.put("password", password);
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String,String> params = new HashMap<String, String>();
// Removed this line if you dont need it or Use application/json
// params.put("Content-Type", "application/x-www-form-urlencoded");
return params;
}
};
但运行后它在logcat 中给了我这个错误:
BasicNetwork.performRequest: Unexpected response code 400
我读过this link,但这对我没有帮助。我很困惑我的代码有什么问题?
【问题讨论】:
-
您是否尝试过从hurl.it等其他来源发送请求
-
@DennisvanOpstal 我之前在没有 Volley 的情况下使用过这项服务,效果很好
-
@DennisvanOpstal 我在 hurl.it 中测试了我的地址,它给了我 404!我厌倦了挣扎
-
应该有404的错误信息,如果有,是什么意思