1

I am calling to a Rest API hosted in IIS (localhost) as in following code.

    HttpPost request = new HttpPost("https://localhost/Identity/oauth/"+"token");   
    request.addHeader("content-type", "application/json");
    request.addHeader("Accept", "application/json");

    List<NameValuePair> params = new ArrayList<NameValuePair>(2);
    params.add(new BasicNameValuePair("username", "myuser"));
    params.add(new BasicNameValuePair("password", "mypass"));
    params.add(new BasicNameValuePair("grant_type", "password"));
    request.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));

    HttpResponse result = httpClient.execute(request);

But it is giving following error.

hostname in certificate didn't match:

What I did wrong in this calling to HTTPS? The HTTP call is working fine though.

Thank you.

  • Have you tried connecting to the actual domain mentioned in the certificate, instead of connecting to `localhost`? – S.L. Barth Jan 17 '17 at 08:26
  • Doesn't that post answer your question ? http://stackoverflow.com/questions/1666052/java-https-client-certificate-authentication – niilzon Jan 17 '17 at 08:29

1 Answers1

0

What kind of certificate you are using in IIS ? Is it self-signed or acquired from a CA ? The problem here is you need to map the Certificate's domain to the domain you call in.

Your certificate is into registered into localhost. If your certificate is registered to abc.com alter your https call as follows.

HttpPost request = new HttpPost("https://abc. com/Identity/oauth/"+"token");   
    request.addHeader("content-type", "application/json");