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.

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");