2016-03-06 83 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);