HTTPS request using volley
Asked Answered
B

2

1

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

Babbling answered 4/2, 2014 at 14:39 Comment(0)
R
3

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!

Realty answered 6/8, 2014 at 18:58 Comment(3)
Hey, I am able to visit my https link in browser but the exact same link always get 404 when trying out in my android app. Please help on this. Thanks in advance.Tyndale
Turned out that it was get post related issue.Tyndale
so you mean that no need to change anything except http to https in case i use https with volley?Mcavoy
S
1

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;
}
Samul answered 5/2, 2014 at 12:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.