title: Java SSLException: hostname in certificate didn't match
body: <p>I have been using the following code to connect to one of google's service. This code worked fine on my local machine :</p>
  
  <pre><code>HttpClient client=new DefaultHttpClient();
  HttpPost post = new HttpPost("https://www.google.com/accounts/ClientLogin");
  post.setEntity(new UrlEncodedFormEntity(myData));
  HttpResponse response = client.execute(post);
  </code></pre>
  
  <p>I put this code in a production environment, which had blocked Google.com. On request, they allowed communication with Google server by allowing me to accessing an IP : 74.125.236.52 - which is one of Google's IPs. I edited my hosts file to add this entry too.</p>
  
  <p>Still I could not access the URL, which I wonder why. So I replaced the above code with :</p>
  
  <pre><code>HttpPost post = new HttpPost("https://74.125.236.52/accounts/ClientLogin");
  </code></pre>
  
  <p>Now I get an error like this :</p>
  
  <blockquote>
    <p>javax.net.ssl.SSLException: hostname in certificate didn't match:
    &lt;74.125.236.52&gt; != &lt;www.google.com&gt;</p>
  </blockquote>
  
  <p>I guess this is because Google has multiple IPs. I cant ask the network admin to allow me access to all those IPs - I may not even get this entire list. </p>
  
  <p>What should I do now ? Is there a workaround at Java level ? Or is it totally in hands of the network guy ?</p>