title: WinHTTP Send Request returns error 12007 (server name cannot be resolved)
body: <p>I've got a couple of users who are getting errors when they attempt to activate one of my programs and the description of the error code being returned is 'The server name cannot be resolved.'  I've got WinHTTP trying to auto-detect proxy settings, but no settings are detected.  It's able to establish a session, but WinHttpSendRequest fails.  I'm waiting on more information from the users about their connections, but I figured I'd post here to see if anyone could find anything wrong with my code.  I've had a really hard time finding useful documentation or samples on the WinHTTP code, so if anyone could recommend a better source than MSDN, I'd be eternally grateful.</p>
  
  <p>Here is my code that initializes the request:</p>
  
  <pre><code>WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ProxyConfig;
  
  memset(&amp;ProxyConfig, 0, sizeof(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG));
  
  BOOL bGetProxyConfig = WinHttpGetIEProxyConfigForCurrentUser(&amp;ProxyConfig);
  if (bGetProxyConfig &amp;&amp; ProxyConfig.lpszProxy &amp;&amp; ProxyConfig.lpszProxyBypass)
  {
      m_hHttpSession = ::WinHttpOpen(  m_strAgentName.c_str(), 
                      WINHTTP_ACCESS_TYPE_NAMED_PROXY,
                      ProxyConfig.lpszProxy, 
                      ProxyConfig.lpszProxyBypass, 0);
  
  
  }
  else
  {
      m_hHttpSession = ::WinHttpOpen(  m_strAgentName.c_str(), 
          WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
          WINHTTP_NO_PROXY_NAME, 
          WINHTTP_NO_PROXY_BYPASS, 0);
  
  }
  
  
  if (m_hHttpSession)
  {
      INTERNET_PORT nPort = INTERNET_DEFAULT_HTTPS_PORT;
  
      if (!m_bUseSSL)
      {
          nPort = INTERNET_DEFAULT_HTTP_PORT;
      }
  
      if (m_hHttpSession)
          m_hInternetConnection = ::WinHttpConnect( m_hHttpSession, m_szHostName,
                                     nPort, 0);
  
      if (m_hInternetConnection)
      {
          WINHTTP_AUTOPROXY_OPTIONS  AutoProxyOptions;
          WINHTTP_PROXY_INFO         ProxyInfo;
          DWORD                      cbProxyInfoSize = sizeof(ProxyInfo);
  
          ZeroMemory( &amp;AutoProxyOptions, sizeof(AutoProxyOptions) );
          ZeroMemory( &amp;ProxyInfo, sizeof(ProxyInfo) );
  
          // Use auto-detection because the Proxy 
          // Auto-Config URL is not known.
          AutoProxyOptions.dwFlags = WINHTTP_AUTOPROXY_AUTO_DETECT;
  
          // Use DHCP and DNS-based auto-detection.
          AutoProxyOptions.dwAutoDetectFlags = 
              WINHTTP_AUTO_DETECT_TYPE_DHCP |
              WINHTTP_AUTO_DETECT_TYPE_DNS_A;
  
          // If obtaining the PAC script requires NTLM/Negotiate
          // authentication, then automatically supply the client
          // domain credentials.
          AutoProxyOptions.fAutoLogonIfChallenged = TRUE;
  
          //
          // Call WinHttpGetProxyForUrl with our target URL. If 
          // auto-proxy succeeds, then set the proxy info on the 
          // request handle. If auto-proxy fails, ignore the error 
          // and attempt to send the HTTP request directly to the 
          // target server (using the default WINHTTP_ACCESS_TYPE_NO_PROXY 
          // configuration, which the requesthandle will inherit 
          // from the session).
          //
  
          BOOL bReturn = FALSE;
  
          if( WinHttpGetProxyForUrl( m_hHttpSession,
              m_strFullUrl.c_str(),
              &amp;AutoProxyOptions,
              &amp;ProxyInfo))
          {
              // A proxy configuration was found, set it on the
              // request handle.
  
              if( !WinHttpSetOption( hHttpRequest, 
                  WINHTTP_OPTION_PROXY,
                  &amp;ProxyInfo,
                  cbProxyInfoSize ) )
              {
                  // Exit if setting the proxy info failed.
                  bReturn = FALSE;
              }
              else
              {
                  bReturn = TRUE;
              }
          }
  
          if( ProxyInfo.lpszProxy != NULL )
              GlobalFree(ProxyInfo.lpszProxy);
  
          if( ProxyInfo.lpszProxyBypass != NULL )
              GlobalFree( ProxyInfo.lpszProxyBypass );
      }
  }
  </code></pre>