Discussion:
WinHttpSendRequest returns error 87 only on one site
(too old to reply)
RobertD
2010-10-22 21:37:26 UTC
Permalink
Dear Anyone who can help:
I am using the following code to do an HTTP GET, and it works fine
almost everywhere. However, for one specific URL it fails with an
error 87. Can anyone explain why that would be, and how I solve the
problem?

USES_CONVERSION;

const char* hostname; // name of the host (without query string)
const char* options; // query string to follow the host name
DWORD myerrno;

hostname = "64.131.242.23:8000";
options = "safetogo/login.jsp";

BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;


hSession = WinHttpOpen( L"MySite HTTP/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);

if (!hSession)
{
return false;
}



hConnect = WinHttpConnect( hSession, T2W(hostname),
INTERNET_DEFAULT_HTTP_PORT, 0);


if (!hConnect)
{
return false;
}


hRequest = WinHttpOpenRequest( hConnect, L"GET",
T2W(options),
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_REFRESH);
if (!hRequest)
{
return false;
}



// Send a request.
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
WINHTTP_NO_REQUEST_DATA, 0, 0,
0);

if (!bResults)
{
myerrno = GetLastError();
return false;
}


// End the request.
if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);



Regards and thanks!
RobertD
OliverM
2010-10-24 18:39:58 UTC
Permalink
Error code 87 is ERROR_INVALID_PASSWORD. That sounds strange - are you
sure?

a) Which function is returning this code?

b) From the very first glance, passing INTERNET_DEFAULT_HTTP_PORT for
a host with port 8000 seems plain wrong according to the msdn docs.

Regards
Oliver
RobertD
2010-10-25 18:44:35 UTC
Permalink
Post by OliverM
Error code 87 is ERROR_INVALID_PASSWORD. That sounds strange - are you
sure?
a) Which function is returning this code?
b) From the very first glance, passing INTERNET_DEFAULT_HTTP_PORT for
a host with port 8000 seems plain wrong according to the msdn docs.
Regards
Oliver
a) The function was WinHttpSendRequest.
b) Thank you very much! This solved the problem. I removed the :8000
suffix from the hostname, and passed the port 8000 as part of the
WinHttpConnect function, and it worked. The corrected corrected code
is:

USES_CONVERSION;

const char* hostname; // name of the host (without query
string)
const char* options; // query string to follow the host
name
DWORD myerrno;

// this did not work ----> hostname = "64.131.242.23:8000";
// the following does work:
hostname = " "64.131.242.23";
options = "safetogo/login.jsp";

BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;

hSession = WinHttpOpen( L"MySite HTTP/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);

if (!hSession)
{
return false;
}

hConnect = WinHttpConnect( hSession, T2W(hostname), 8000, 0);

if (!hConnect)
{
return false;
}

hRequest = WinHttpOpenRequest( hConnect, L"GET",
T2W(options),
NULL, WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
WINHTTP_FLAG_REFRESH);
if (!hRequest)
{
return false;
}

// Send a request.
bResults = WinHttpSendRequest( hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS,
0,
WINHTTP_NO_REQUEST_DATA, 0, 0,
0);

if (!bResults)
{
myerrno = GetLastError();
return false;
}

// End the request.
if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);

Loading...