خرید بک لینک

Vote count: 0

I want to use volley to build http coection with authentication. Following this answer I add the segment

  @Override
                    public Map<String, String> getHeaders() throws AuthFailureError {
                        HashMap<String, String> params = new HashMap<String, String>();
                        String creds = String.format("%s:%s","USERNAME","PASSWORD");
                        String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
                        params.put("Authorization", auth);
                        retu params;
                    }

in Anonymous Ier Class StringRequest , and it looks like:

StringRequest stringRequest = new StringRequest(Request.Method.GET, url,
        new Response.Listener<String>() {


//the segment below is what I add 
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                HashMap<String, String> params = new HashMap<String, String>();
                String creds = String.format("%s:%s","USERNAME","PASSWORD");
                String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
                params.put("Authorization", auth);
                retu params;
            }

//the segment above is what I add 
            @Override
            public void onResponse(String response) {
                // Display the first 500 characters of the response string.
            }
        }, new Response.ErrorListener() {
    @Override
    public void onErrorResponse(VolleyError error) {
    }
});

However, IDE hints that getHeaders() doesn't override its superclass.

Why?I found that StringRequest extends class Request<String>, and the latter does have a method called getHeaders().

asked 2 mins ago

برچسب: نویسنده: استخدام کار تاريخ: دوشنبه 13 ارديبهشت 1395 ساعت: 13:15

صفحه بندی