Bakus123
Bakus123

Reputation: 1399

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 to standard http request?

I read this tutorial - http://ogrelab.ikratko.com/using-android-volley-with-self-signed-certificate/ but it's is about self-signed SSL certificate.

I will be grateful for any help

Upvotes: 1

Views: 10794

Answers (2)

settheline
settheline

Reputation: 3383

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!

Upvotes: 3

maxxxo
maxxxo

Reputation: 754

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;
}

Upvotes: 1

Related Questions