我有这个错误:
Volley: [8918] BasicNetwork.performRequest: Unexpected response code 403 for
Run Code Online (Sandbox Code Playgroud)
我正在尝试连接到服务器,但我无法检索任何内容。当我在本地主机服务器中尝试它时,它运行良好。
我试图从GET请求发送一些身份验证标头,我尝试使用Volley JsonObjectRequest调用:
Map<String,String> params=new HashMap<String,String>();
params.put("token","fghjbvjhnjjk");
activity.showDialog();
JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET,url,
new JSONObject(params), new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(tag, response.toString());
activity.hideDialog();
try {
activity.onRequestServed(response, code);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(tag, "Error: " + error.getMessage());
Log.e(tag, "Site Info Error: " + error.getMessage());
Toast.makeText(activity.getApplicationContext(),
error.getMessage(), Toast.LENGTH_SHORT).show();
activity.hideDialog();
try {
activity.onRequestServed(null,code);
} catch (JSONException e) {
e.printStackTrace();
}
}
}); …Run Code Online (Sandbox Code Playgroud)