Discussion:
HttpSendRequest fails on Windows XP SP2
(too old to reply)
JeffM
2004-10-06 22:40:21 UTC
Permalink
After installing Service Pack 2 for Windows XP, my Wininet code to post
form data,
which worked perfectly before, now fails.


This is the response I get back:
<h1>Bad Request</h1>

The headers I get back:
HTTP/1.1 400 Bad Request
Content-Type: text/html
Date: Wed, 06 Oct 2004 06:27:21 GMT
Connection: close
Content-Length: 20


This is how I setup the post:

TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded");
TCHAR accept[] = _T("*/*");

HINTERNET hSession = InternetOpen( myagent, INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0 );
HINTERNET hConnect = InternetConnect( hSession, myurl,
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1 );
HINTERNET hRequest = HttpOpenRequest( hConnect, _T("POST"), mypage,
_T("HTTP/1.0"), NULL, (const char**)accept, 0, 1 );

HttpSendRequest( hRequest, hdrs, strlen(hdrs), (void*)LPCSTR(formdata),
strlen(formdata) );


How can I post form data using Wininet on Windows XP SP2?
What is SP2 doing to my HTTP request?
Stephen Sulzer
2004-10-07 09:07:38 UTC
Permalink
This may not be related to the cause of the problem, but there is a bug in
your code:

The accept string array variable is not declared correctly. For the
lplpszAcceptTypes parameter, HttpOpenRequest expects an array of strings
terminated by a NULL array element. This is not what your code is doing. So
your accept variable declaration should look like this instead:

const TCHAR * accept[] = { _T("*/*"), NULL };

With this declaration for accept, there should be no need for the (const
char **) cast.
JeffM
2004-10-07 21:05:17 UTC
Permalink
Thank you very much! It's now working.

I was using the code directly from the article entitled

"HOWTO: Simulate a Form POST Request Using WinInet"
http://support.microsoft.com/default.aspx?scid=kb;EN-US;165298

And it looks like someone has updated the article since I last read it.
The old article may have had a bug in it.

It looks like someone changed a line to:

static LPSTR accept[2]={"*/*", NULL};

which is exactly what you suggested.

Thanks.

Loading...