Skip to content Skip to sidebar Skip to footer

HTTPS Request Using Volley

Could somebody show me any example how execute POST or GET request using volley library to server with certificate issued by a well known CA? Do I have to change anything compare t

Solution 1:

I looked around to find an answer for this also. For me, I found it was as easy as changing my request URL from:

http://www.myserver.com/whatever

to

https://www.myserver.com/whatever

This may depend on your server and DNS settings. For instance, I redirect my root domain:

https://myserver.com to https://www.myserver.com. It's a Heroku thing...

When I tried to make requests to the root domain, I got 301 responses from the server as it tried to redirect to the www subdomain. Just keep in mind your DNS settings. Hope this helps someone!


Solution 2:

This is how I am using it:

public Request<?> deleteUser(String id, final String loginName, final String password,
                                     Response.Listener responseListener,
                                     Response.ErrorListener errorListener) {

    final int method = Request.Method.DELETE;
    final Map<String, String> authHeaders = getAuthHeaders(loginName, password);

    StringRequest request = new StringRequest(method, url, responseListener, errorListener) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            return authHeaders;
        }
    };

    return mQueue.add(request);
}


public Map<String, String> getAuthHeaders(String loginName, String password) {
    HashMap<String, String> params = new HashMap<String, String>();
    String creds = String.format("%s:%s", loginName, password);
    String auth = "Basic " + Base64.encodeToString(creds.getBytes(), Base64.DEFAULT);
    params.put("Authorization", auth);
    return params;
}

Post a Comment for "HTTPS Request Using Volley"