2014-10-07 100 views
1

我使用齊射爲登錄功能,但我得到意外的響應代碼400爲https。 它適用於wifi,但不適用於蜂窩網絡,而且問題只發生在選定的手機型號上。下面我粘貼了我的代碼。公共無效LoginRequest(最終的字符串用戶名,最終的字符串密碼,最終的ActionResponse成功,最終的行動錯誤){ RequestQueue隊列= MVolleyRequests.getInstance(mContext).getRequestQueue();Android Volley意外的響應代碼400

StringRequest sr = new StringRequest(com.android.volley.Request.Method.POST,LOGIN_URL, 
      new Listener<String>() { 
     @Override 
     public void onResponse(String response) { 
      success.action(MError.getError(Integer.parseInt(response))); 
     } 
    }, new ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      err.action(); 
     } 
    }){ 

     @Override 
     protected Map<String,String> getParams(){ 
      Map<String,String> params = new HashMap<String, String>(); 
      params.put("id", username); 
      params.put("pwd", password); 
      params.put("version", "2.5"); 
      return params; 
     } 
     @Override 
     public Map<String, String> getHeaders() throws AuthFailureError { 
      Map<String,String> params = new HashMap<String, String>(); 
      params.put("Content-Type","application/x-www-form-urlencoded; charset=utf-8"); 
      return params; 
     } 
    }; 
    sr.setRetryPolicy(new DefaultRetryPolicy(
      60000, 
      DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
      DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 
    MVolleyRequests.getInstance(mContext).addToRequestQueue(sr); 

} 
+0

你打給哪個網址? – 2014-10-07 14:09:37

+0

@ A.S。它是一個https鏈接 – 2014-10-07 15:12:30

回答

3

嘗試了這一點:

的JSONObject PARAMS =新的JSONObject();

try { 
    params.put("id", username); 
      params.put("pwd", password); 
      params.put("version", "2.5"); 
} catch (JSONException e) { 
    // TODO Auto-generated catch block 
    e.printStackTrace(); 
} 
// 

JsonObjectRequest jsonObjReq = new JsonObjectRequest(Method.POST, 
     url, params, 
     new Response.Listener<JSONObject>() { 

      @Override 
      public void onResponse(JSONObject response) { 
       Log.d(TAG, response.toString()); 
      } 
     }, new Response.ErrorListener() { 

      @Override 
      public void onErrorResponse(VolleyError error) { 
       VolleyLog.d(TAG, "Error: " + error.getMessage()); 
      } 
     }) { 

    /** 
    * Passing some request headers 
    * */ 
    @Override 
    public Map<String, String> getHeaders() throws AuthFailureError { 
     HashMap<String, String> headers = new HashMap<String, String>(); 
     headers.put("Content-Type", "application/json; charset=utf-8"); 
     return headers; 
    } 

}; 
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(60000, 
     DefaultRetryPolicy.DEFAULT_MAX_RETRIES, 
     DefaultRetryPolicy.DEFAULT_BACKOFF_MULT)); 

// Adding request to request queue 
getRequestQueue(jsonObjReq); 
相關問題