0

I am using Volley's JsonArrayRequest to get JSON data from my webpage. Now I have added Basic HTTP Authentication to my webpage. How can I use HTTP Auth with Volley? And further if I add Digest HTTP Authentication to my webpage, How can I deal with it in android?

My JsonArrayRequest code:

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);
MrShadow
  • 171
  • 3
  • 16
  • Do you want to find this ? http://stackoverflow.com/questions/16817980/how-does-one-use-basic-authentication-with-volley-on-android – xxxzhi Mar 06 '16 at 11:20

1 Answers1

0

Use RequestQueue and StringRequest instead like so

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);  
Jyotman Singh
  • 10,792
  • 8
  • 39
  • 55
Aliyu Abdullahi
  • 129
  • 1
  • 4