【问题标题】:How to use HTTP Auth with Volley如何在 Volley 中使用 HTTP Auth
【发布时间】:2016-03-06 21:30:23
【问题描述】:

我正在使用VolleyJsonArrayRequest 从我的网页获取 JSON 数据。 现在我已将 Basic HTTP 身份验证 添加到我的网页。如何将 HTTP AuthVolley 一起使用? 此外,如果我将 Digest HTTP Authentication 添加到我的网页,我该如何在 android 中处理它?

我的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);

【问题讨论】:

标签: android android-volley http-authentication


【解决方案1】:

像这样使用 RequestQueue 和 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);  

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-30
    • 1970-01-01
    相关资源
    最近更新 更多