2016-03-06 37 views
0

我正在使用VolleyJsonArrayRequest從我的網頁獲取JSON數據。 現在我已將基本 HTTP身份驗證添加到我的網頁。如何使用 HTTP驗證碼Volley? 如果我在網頁中添加Digest HTTP Authentication,我該如何在android中處理它?如何使用HTTP Auth與Volley

JsonArrayRequest代碼:

JsonArrayRequest loadMoreRequest = new JsonArrayRequest(url,new Response.Listener<JSONArray>() 
{ 
    @Override 
    public void onResponse(JSONArray response) 
    { 
     try 
     { 
      for (int i = 0; i < response.length(); i++) 
      { 
       JSONObject obj = response.getJSONObject(i); 
       //Some Logic 
      } 
     } 
     catch (JSONException e) 
     { 
      e.printStackTrace(); 
     } 
    } 
}, 
new Response.ErrorListener() 
{ 
    @Override 
    public void onErrorResponse(VolleyError error) 
    { 
     Toast.makeText(getActivity(), error.toString(),Toast.LENGTH_LONG).show(); 
    } 
}); 
requestQueue.add(loadMoreRequest); 
+0

你想找到這個? http://stackoverflow.com/questions/16817980/how-does-one-use-basic-authentication-with-volley-on-android – xxxzhi

回答

0

使用請求隊列和StringRequest,而不是像這樣

RequestQueue queue = Volley.newRequetQueue(context); 

StringRequest myReq = new StringRequest(Method.POST,          "http://ave.bolyartech.com/params.php", 
             createMyReqSuccessListener(), 
             createMyReqErrorListener()) { 
    protected Map<string, string=""> getParams() throws com.android.volley.AuthFailureError { 
     Map<string, string=""> params = new HashMap<string, string="">(); 
     params.put("param1", num1); 
     params.put("param2", num2); 
     return params; 
    }; 
}; 

queue.add(myReq);