2016-11-24 63 views
0

我不明白我的代碼有什麼問題,我想發送一個帶頭和參數的抽象請求,參數格式將是「application/x-www-form-urlencoded」。VOLLEY 500和400錯誤

我得到,當我使用此代碼

 @Override 
     public Map<String, String> getHeaders() throws AuthFailureError { 
      Map<String, String> params = new HashMap<String, String>(); 
      params.put("Token", "1234); 
      params.put("Content-Type", "application/x-www-form-urlencoded"); 
      return params; 
     } 

,當我使用此代碼

@Override 
    public Map<String, String> getHeaders() throws AuthFailureError { 
     Map<String, String> params = new HashMap<String, String>(); 
     params.put("Token", "1234); 
     return params; 
    } 

和整體功能得到500錯誤400錯誤

public void requestWithSomeHttpHeaders() { 

    RequestQueue queue = Volley.newRequestQueue(this); 

    StringRequest postRequest = new StringRequest(Request.Method.POST,"http://12.211.156.201/SOWebService/Service.asmx/GetCompany", 
      new Response.Listener<String>() 
      { 
       @Override 
       public void onResponse(String response) { 
        System.out.println(response); 

       } 
      }, 
      new Response.ErrorListener() 
      { 
       @Override 
       public void onErrorResponse(VolleyError error) { 

        System.out.println(error.toString() + "--" + error.getCause()); 

        // TODO Auto-generated method stub 
        Log.d("ERROR","error => "+error.toString()); 
        // definitions.setText("check your internet connection"); 
        if (error instanceof TimeoutError || error instanceof NoConnectionError) { 
         System.out.println("1"); 
        } else if (error instanceof AuthFailureError) { 
         System.out.println("2"); 
         //TODO 
        } else if (error instanceof ServerError) { 
         System.out.println("3"); 
         //TODO 
        } else if (error instanceof NetworkError) { 
         System.out.println("4"); 
         //TODO 
        } else if (error instanceof ParseError) { 
         System.out.println("5"); 
         //TODO 
        } 
       } 
      } 
    ) 

    { 
     @Override 
     public Map<String, String> getHeaders() throws AuthFailureError { 
      Map<String, String> params = new HashMap<String, String>(); 
      params.put("Token", token); 
      return params; 
     } 

     @Override 
     protected Map<String, String> getParams() throws AuthFailureError { 
      // return super.getParams(); 
      Map<String, String> params = new HashMap<String, String>(); 
      params.put("groupName", "avd"); 
      params.put("userCode", "ADMIN"); 

      return params; 
     } 

    }; 
    queue.add(postRequest); 

} 

回答