You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Richard Gundersen <Ri...@pharos.tv> on 2010/09/14 18:05:36 UTC

hostname in certificate didn't match

Hi

When I make a connection with HttpClient 4.0.1, I get this message:

hostname in certificate didn't match: <1.2.3.4> != <*.testing.com>

However when I go to my site in any browser, the certificate is for "*.testing.com" so I was wondering where the hostname is being converted to an IP address. In my code (where I make the connection) I use the hostname "something.testing.com" which as far as I can make out, should work.

I'm quite new to this, and this seems to be slightly different to other posts I've found on the same exception so if anyone could give me some tips I would really appreciate it.

Thanks

Richard

PS This is my code by the way (I'm using BASIC authentication as the site uses authentication)

  String url = protocol + "://" + hostname + ":" + port + path;
        log.debug("Authenticating user " + userName + " against URL: " + url);

        // Set up the connection objects
        DefaultHttpClient httpclient = new DefaultHttpClient();

        httpclient.getCredentialsProvider().setCredentials(
                new AuthScope(hostname, port, AuthScope.ANY_REALM, authScheme),
                new UsernamePasswordCredentials(userName, password));

        HttpGet httpget = new HttpGet(url);

        log.debug("Executing request " + httpget.getRequestLine());
        HttpResponse response = httpclient.execute(httpget);


________________________________
This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender (as shown above). Kindly do not reproduce, print or forward any material received in error, please delete it immediately. Pharos Communications Limited (Company No. 3458137) is incorporated in England and Wales and has its registered office at 83 London Street, Reading, Berkshire, UK, RG1 4QA.
Pharos Communications Pte Limited (Company No. 200817005N) is incorporated in Singapore and has its registered office at One Marina Boulevard, #28-00. Singapore 018989

RE: hostname in certificate didn't match

Posted by Richard Gundersen <Ri...@pharos.tv>.
Hmm, I tried this too in case it was a problem with the default hostname verifier, but I still have the same problem:

          String url = protocol + "://" + hostname + ":" + port + path;
        log.debug("Authenticating user " + userName + " against URL: " + url);

        HttpParams params = new BasicHttpParams();
        HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
        HttpProtocolParams.setContentCharset(params, "UTF-8");
        int timeoutConnection = 3000;
        HttpConnectionParams.setConnectionTimeout(params, timeoutConnection);
        int timeoutSocket = 5000;
        HttpConnectionParams.setSoTimeout(params, timeoutSocket);
        SchemeRegistry registry = new SchemeRegistry();
        registry.register(new Scheme("http", PlainSocketFactory
                        .getSocketFactory(), 80));
        final SSLSocketFactory sslSocketFactory = SSLSocketFactory
                        .getSocketFactory();
        sslSocketFactory
                        .setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
        registry.register(new Scheme("https", sslSocketFactory, 443));

        ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(
                        params, registry);

        DefaultHttpClient httpclient = new DefaultHttpClient(manager, params);



-----Original Message-----
From: Richard Gundersen [mailto:Richard.Gundersen@pharos.tv]
Sent: 14 September 2010 17:06
To: httpclient-users@hc.apache.org
Subject: hostname in certificate didn't match

Hi

When I make a connection with HttpClient 4.0.1, I get this message:

hostname in certificate didn't match: <1.2.3.4> != <*.testing.com>

However when I go to my site in any browser, the certificate is for "*.testing.com" so I was wondering where the hostname is being converted to an IP address. In my code (where I make the connection) I use the hostname "something.testing.com" which as far as I can make out, should work.

I'm quite new to this, and this seems to be slightly different to other posts I've found on the same exception so if anyone could give me some tips I would really appreciate it.

Thanks

Richard

PS This is my code by the way (I'm using BASIC authentication as the site uses authentication)

  String url = protocol + "://" + hostname + ":" + port + path;
        log.debug("Authenticating user " + userName + " against URL: " + url);

        // Set up the connection objects
        DefaultHttpClient httpclient = new DefaultHttpClient();

        httpclient.getCredentialsProvider().setCredentials(
                new AuthScope(hostname, port, AuthScope.ANY_REALM, authScheme),
                new UsernamePasswordCredentials(userName, password));

        HttpGet httpget = new HttpGet(url);

        log.debug("Executing request " + httpget.getRequestLine());
        HttpResponse response = httpclient.execute(httpget);


________________________________
This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender (as shown above). Kindly do not reproduce, print or forward any material received in error, please delete it immediately. Pharos Communications Limited (Company No. 3458137) is incorporated in England and Wales and has its registered office at 83 London Street, Reading, Berkshire, UK, RG1 4QA.
Pharos Communications Pte Limited (Company No. 200817005N) is incorporated in Singapore and has its registered office at One Marina Boulevard, #28-00. Singapore 018989

This e-mail and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this e-mail in error please notify the sender (as shown above). Kindly do not reproduce, print or forward any material received in error, please delete it immediately. Pharos Communications Limited (Company No. 3458137)  is incorporated in England and Wales and has its registered office at 83 London Street, Reading, Berkshire, UK, RG1 4QA.
Pharos Communications Pte Limited (Company No. 200817005N) is incorporated in Singapore and has its registered office at One Marina  Boulevard, #28-00. Singapore 018989

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org