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).
But some of our customers, that uses this service and_proxy_with_authorization 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.
Proxy configuration seems to be correct. Here is initialization 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)(&proxyinfo), sizeof(proxyinfo));
if (!B)
{
devent(TS::LL_HIGH, "[Wrn] InternetSetOption::Proxy failed <proxy=%s><le=%d>",
m_strProxyServer.c_str(),
GetLastError());
}
}
// Validate handle
if (NULL == m_hNet)
{
devent(TS::LL_CRITICAL, "[Err] InternetOpen failed <le=%d>",
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 <le=%d>",
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 <login=%s><le=%d>",
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 <pass=%s><le=%d>",
Cfg::m_strProxyPassword.c_str(),
GetLastError());
}
}
And this is sending:
// 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 <le=%d>",
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 <le=%d>",
GetLastError());
CloseHandle(m_hRequest);
return false;
}
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?
Any ideas?