title: HTTPS hostname wrong: should be <sub.domain.com>. What causes this?
body: <p>I am getting this 'HTTPS hostname wrong:' error when trying to connect to a server using https. My url looks something like this</p>
  
  <pre><code>https://sub.domain.com/tamnode/webapps/app/servlet.
  </code></pre>
  
  <p>I connect using the following code</p>
  
  <pre><code>    // Create a URLConnection object for a URL
      URL url = new URL(requestedURL);
      HttpURLConnection.setFollowRedirects(false);
  
      // connect
      connection = (HttpURLConnection) url.openConnection();
      connection.setDoOutput(true);
      connection.setRequestProperty("User-Agent", USER_AGENT); //$NON-NLS-1$
  
      OutputStreamWriter wr = new OutputStreamWriter(connection
              .getOutputStream());
  </code></pre>
  
  <p>but then get an error </p>
  
  <pre><code>IOException: HTTPS hostname wrong:  should be &lt;sub.domain.com&gt;. 
      at sun.net.www.protocol.https.HttpsClient.checkURLSpoofing
      ....
  </code></pre>
  
  <p>This is code which has worked in the past but no longer. There have been some changes to the system architecture but I need to get more data before approaching those responsible.</p>
  
  <p>What can cause this error? Can I turn off the URLSpoofing check?</p>