0

I have to connect to a secured https url and I followed these steps:

  1. Create the HttpClient :
client = new DefaultHttpClient();
HostnameVerifier hostnameVerifier = org.apache.http.conn.ssl.SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier) hostnameVerifier);

registry.register(new Scheme("https", socketFactory, 443));
registry.register(new Scheme("http", socketFactory, 80));
SingleClientConnManager mgr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mgr, client.getParams());  
HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);

2. I create a HttpPost:

HttpPost post = new HttpPost("");
post.setHeader("Content-Type",  "application/json");
post.setHeader("TOKEN", token);
post.setHeader("Accept", "*/*");
HttpEntity e = new StringEntity(json.toString());
post.setEntity(e);

3. I executed the request:

HttpResponse response = httpClient.execute(post);

The response shows that access is denied.

Can somebody help me to understand what I'm doing wrong?

Stu Mackellar
  • 11,510
  • 1
  • 38
  • 59
user880386
  • 2,737
  • 7
  • 33
  • 41
  • Sometimes, allowing all hosts is not enough. It could be that the other end is requesting a Client Certificate and you're not providing one. – Davio Jul 15 '14 at 09:33
  • "Access Denied" is usually a message from the server indicating that your request misses or contains wrong authentication data like username/password or an authentication token. If the data is correct the used account may be does not have the permission to execute the function you want to use. – Robert Jul 16 '14 at 11:57

0 Answers0