从两天我试图解决这个问题,但我仍然没有任何结果,为什么每次都凌空回国403错误。我错在哪里?我使用邮递员检查相同的webservice,它返回成功结果。但同样的事情,当我通过volley或httpurlconnection得到403 error.kindly帮助我找到我的错误在Android中使用。排球回归403错误
这是我的代码,我曾尝试:
StringRequest jsonObjectRequest = new StringRequest(Request.Method.POST, Constant.posturl, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
String result=response;
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
NetworkResponse response = error.networkResponse;
int status = response.statusCode;
}
}) {
@Override
public Map<String, String> getHeaders() {
try {
headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
String credentials = Constant.USERNAME + ":" + Constant.PASSWORD;
String auth = "Basic " + Base64.encodeToString(credentials.getBytes(), Base64.DEFAULT);
headers.put("Authorization", auth);
return headers;
} catch (Exception e) {
e.printStackTrace();
return headers;
}
}
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("title", heading_edit_text.getText().toString());
params.put("content", body_edit_text.getText().toString());
params.put("Slug", heading_edit_text.getText().toString());
params.put("date", currentDate);
return params;
}
};
jsonObjectRequest.setRetryPolicy(new DefaultRetryPolicy(50000, 3, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
requestQueue.add(jsonObjectRequest);
403将被禁止。你能否在这里复制邮递员请求(修改任何应该是私人的东西!)。你可以,在邮递员单击代码链接并复制HTTP ... –
@Redman我的用户名和密码是正确的,因为我在邮递员也使用相同的用户名和密码also.postman返回成功的结果。 – Rims
你应该检查base64编码的标记是否符合你的邮递员请求和应用程序请求 – akash93