如何在排球Android

时间:2017-09-11 14:33:32

标签: android api android-volley

当我点击Postman上的api时,它给出状态:401,404等。 如何在排球回应Postman response

中获得该状态

1 个答案:

答案 0 :(得分:0)

您可以尝试覆盖getHeaders

StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String s) {
    ///handle response from service
}, new ErrorResponse() {
  @Override
  public void onErrorResponse(VolleyError volleyError) {
    //handle error response
  }
 }) {
  @Override
  protected Map<String, String> getParams() throws AuthFailureError {
      Map<String, String> params = new HashMap<String, String>();
      //add params <key,value>
      return params;
  }

  @Override
  public Map<String, String> getHeaders() throws AuthFailureError {
    Map<String,String> headers = Constants.getHeaders(context);
    // add headers <key,value>
    String credentials = USERNAME+":"+PASSWORD;
    String auth = "Basic "
            + Base64.encodeToString(credentials.getBytes(),
            Base64.NO_WRAP);
    headers.put("Authorization", auth);
    return headers;
  }
};
mQueue.add(request);