title: WinHttpSendRequest fails with ERROR_WINHTTP_SECURE_FAILURE
body: <p>Programmatically communicating with the web is not my area of expertise but I managed to make a read_web_page() function by cutting and pasting code from examples found online and the code has been working without error on a daily basis for many months.</p>
  
  <p>It just so happened that my main windows-10 PC at work broke down and while waiting for it to be repaired and I am now forced to run the (the same) code from a windows-7 PC at home.</p>
  
  <p>But now I have a error appear that I never saw before. I call the following code (simplified):</p>
  
  <pre><code>    // code to handle bad return values from the following three functions ommitted...
  
      HINTERNET hsession = WinHttpOpen(0,WINHTTP_ACCESS_TYPE_DEFAULT_PROXY, WINHTTP_NO_PROXY_NAME,WINHTTP_NO_PROXY_BYPASS, 0);
  
      HINTERNET hconnect = WinHttpConnect(hsession, (LPCWSTR)thewebsite, INTERNET_DEFAULT_HTTPS_PORT , 0);
  
      HINTERNET hrequest = WinHttpOpenRequest(hconnect, L"GET", (LPCWSTR)thesubdirectory, NULL, WINHTTP_NO_REFERER, WINHTTP_DEFAULT_ACCEPT_TYPES, WINHTTP_FLAG_SECURE);
  
      if (!WinHttpSendRequest(hrequest, WINHTTP_NO_ADDITIONAL_HEADERS, 0, WINHTTP_NO_REQUEST_DATA, 0, 0, 0))
      {
          int err = GetLastError();
  </code></pre>
  
  <p>Normally WinHttpSendRequest returns zero but now returns a non-zero value and GetLastError() returns a value of 12175 (equal to ERROR_WINHTTP_SECURE_FAILURE).</p>
  
  <p>The (https) URL I am connecting to has been the same all along and when I type it into my browser, the site still appears as normal.</p>
  
  <p>Maybe the whole change of PC and location is a coincidence and the problem is caused by an under-the-hood change in the website I am reading (it is not under my control)... but I have no idea how to begin diagnosing (or fixing) the fault. Could it be something to do with my ISP?</p>
  
  <p>The <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa384110%28v=vs.85%29.aspx" rel="nofollow noreferrer">documentation for WinHttpSendRequest</a> says that more detailed information can be found for this error by setting up a callback function but the documentation describing how this is done is incomprehensible to me and I can not find any example code anywhere.</p>
  
  <p><strong>EDIT:</strong> To address Barmak's concerns about thewebsite and thesubdirectory, the code that creates them is here below:</p>
  
  <pre><code>char *char_thewebsite = "www.thewebsite.com";
  char *char_thesubdirectory = "sub";
  
  int n_website = MultiByteToWideChar(CP_ACP, 0, char_thewebsite, -1, NULL, 0);
  int n_subdir = MultiByteToWideChar(CP_ACP, 0, char_thesubdirectory, -1, NULL, 0);
  
  thewebsite = new WCHAR[n_website];
  thesubdirectory = new WCHAR[n_subdir];
  
  MultiByteToWideChar(CP_ACP, 0, char_thewebsite, -1, (LPWSTR)thewebsite, n_website);
  MultiByteToWideChar(CP_ACP, 0, char_thesubdirectory, -1, (LPWSTR)thesubdirectory, n_subdir);
  </code></pre>