HTTPS request using volley

后端 未结 2 1051
没有蜡笔的小新
没有蜡笔的小新 2021-01-16 14:04

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 co

相关标签:
2条回答
  • 2021-01-16 14:24

    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!

    0 讨论(0)
  • 2021-01-16 14:38

    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;
    }
    
    0 讨论(0)
提交回复
热议问题