title: HttpSendRequest fails with error 12015
body: <p>I have created a Win32 Service which uses WinInet to send HTTP-requests to remote host. On my computer (WinXP SP2), on test workstations in our QoS-team (Win2003 Server) it works fine - over proxy and direct, proxy with auth and without).</p>
  
  <p>But some of our customers, that uses this service <strong>and_proxy_with_authorization</strong> on Win2003 Server, have a problem - all calls of HttpSendRequest fails and GetLastError returns 12015 (ERROR_INTERNET_LOGIN_FAILURE, The request to connect and log on to an FTP server failed). Herewith, equal HTTP-request, manually sent from IE address-line, succeeded.</p>
  
  <p>Proxy configuration seems to be correct. Here is initialization code:  </p>
  
  <pre><code>m_hNet = InternetOpen(m_strAgent.c_str(),
              INTERNET_OPEN_TYPE_PRECONFIG,
              NULL,
              NULL,
              0);
  
          // Respect explicit proxy
          if (Cfg::m_bUseProxy)
          {
              char szProxy[MAX_PATH] = {0};
              strncpy(szProxy, m_strProxyServer.c_str(), MAX_PATH - 1);
  
              INTERNET_PROXY_INFO proxyinfo;
              proxyinfo.dwAccessType = INTERNET_OPEN_TYPE_PROXY;
              proxyinfo.lpszProxy = szProxy;
              proxyinfo.lpszProxyBypass = NULL;
  
              BOOL B = InternetSetOption(m_hNet, INTERNET_OPTION_PROXY, (LPVOID)(&amp;proxyinfo), sizeof(proxyinfo));
              if (!B)
              {
                  devent(TS::LL_HIGH, "[Wrn] InternetSetOption::Proxy failed &lt;proxy=%s&gt;&lt;le=%d&gt;",
                      m_strProxyServer.c_str(),
                      GetLastError());
              }
          }
  
  
          // Validate handle
          if (NULL == m_hNet)
          {
              devent(TS::LL_CRITICAL, "[Err] InternetOpen failed &lt;le=%d&gt;",
                  GetLastError());
              return false;
          }
  
  
          // Try to get connection handle
          m_hConnect = InternetConnect(m_hNet,
              m_strHostName.c_str(),
              INTERNET_DEFAULT_HTTP_PORT,
              NULL,
              NULL,
              INTERNET_SERVICE_HTTP,
              0,
              0);
  
  
          // Validate handle
          if (NULL == m_hConnect)
          {
              devent(TS::LL_CRITICAL, "[Err] InternetConnect failed &lt;le=%d&gt;",
                  GetLastError());
              Cleanup();
              return false;
          }
  
          // Respect proxy authentication
          if (Cfg::m_bUseAuth)
          {
              BOOL B;
              B = InternetSetOption(m_hConnect, INTERNET_OPTION_PROXY_USERNAME, (LPVOID*)Cfg::m_strProxyLogin.c_str(), Cfg::m_strProxyLogin.length() + 1);
              if (!B)
              {
                  devent(TS::LL_HIGH, "[Wrn] InternetSetOption::ProxyUserName failed &lt;login=%s&gt;&lt;le=%d&gt;",
                      Cfg::m_strProxyLogin.c_str(),
                      GetLastError());
              }
  
              B = InternetSetOption(m_hConnect, INTERNET_OPTION_PROXY_PASSWORD, (LPVOID*)Cfg::m_strProxyPassword.c_str(), Cfg::m_strProxyPassword.length() + 1);
              if (!B)
              {
                  devent(TS::LL_HIGH, "[Wrn] InternetSetOption::ProxyPassword failed &lt;pass=%s&gt;&lt;le=%d&gt;",
                      Cfg::m_strProxyPassword.c_str(),
                      GetLastError());
              }
          }
  </code></pre>
  
  <p>And this is sending:</p>
  
  <pre><code>// Try to get request handle
          m_hRequest = HttpOpenRequest(m_hConnect,
              "POST",
              m_strReqObject.c_str(),
              NULL,
              NULL,
              NULL,
              INTERNET_FLAG_NO_CACHE_WRITE,
              0);
  
          // Validate handle
          if (NULL == m_hRequest)
          {
              devent(TS::LL_CRITICAL, "[Err] OpenRequest failed &lt;le=%d&gt;",
                  GetLastError());
              return false;
          }
  
          // Try to get response
          BOOL bOk = HttpSendRequest(m_hRequest,
              strSpecificHeaders.c_str(),
              strSpecificHeaders.length(),
              (LPVOID)strRequest.c_str(),
              (DWORD)strRequest.length());
  
          if (0 == bOk)
          {
              devent(TS::LL_CRITICAL, "[Err] SendRequest failed &lt;le=%d&gt;",
                  GetLastError());
  
              CloseHandle(m_hRequest);
              return false;
          }
  </code></pre>
  
  <p>I have googled two days, but not found not only solutions but also similar problems by anybody. Also i cannot reproduce problem on similar workstations. And finally, i cant understand why "FTP-Server" in msdn error desc?</p>
  
  <p>Any ideas?</p>