Are you using the WinHTTP Win32 API or the WinHttpRequest COM component?
Can you post an example of your code please?
Regards,
Stephen Sulzer
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"gigino" <invisibil...@yahoo.it> wrote in message
news:5ffb01c28448$7cebb8d0$36ef2ecf@tkmsftngxa12...
Dim bd
bd = request.form("bd")
response.write "body=" & bd & "ENDBD"
But bd is always empty. Here is my relevant code:
CString strFormData = "BD=testbody";
LPCWSTR pwszHeader = L"Content-Type:
application/x-www-form-urlencoded";
hRequest = WinHttpOpenRequest( hConnect, L"POST",
strObject.AllocSysString(),
L"HTTP/1.1", WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES, 0);
bResults = WinHttpSendRequest( hRequest,
pwszHeader,
-1L,
strFormData.AllocSysString(),
strFormData.GetLength(),
strFormData.GetLength(),
0);
I've played around with the different "length" parameters in
SendRequest with no luck and I've also tried calling
WinHttpAddRequestHeaders to set the headers, which also didnt help.
I'm sure it's something real simple that I am missing here.
Thanks for any help,
mike martin
"Stephen Sulzer \(Microsoft\)" <ssu...@online.microsoft.com> wrote in message news:<OQtF2hrhCHA.1392@tkmsftngp12>...
Does strFormData.AllocSysString() return a wide-character Unicode string, or
a single-byte character ANSI string? If it is returning a wide-character
string, then that is likely causing a problem. The WinHttpSendRequest API
expects a pointer to BYTE or single-character string data, not
wide-character string data.
Regards,
Stephen Sulzer
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"mike martin" <mma...@notifycorp.com> wrote in message
news:de469d9e.02110...@posting.google.com...
"Stephen Sulzer [Microsoft]" <ssu...@online.microsoft.com> wrote in message news:<#xoHlF7hCHA.2156@tkmsftngp12>...
I'm using the Winhttp win32 API; the segment of code i wrote to post
data to a server is the following; i followed an example of winhttp
help in which there was only the download of an html page and i've
made the changes i thought i needed to post data, but it doesn't
work...
"CS=friuli" is the string i want to post, the page is
www.myservarname.it/rs/find.asp; the error i get is 12002 (timeout),
but the problem seems to be the post... if i only read the page
without posting data, there is no problem.
Thank you for any help
Gigino
DWORD dwSize = 0;
DWORD dwDownloaded = 0;
LPSTR pszOutBuffer;
BOOL bResults = FALSE;
HINTERNET hSession = NULL,
hConnect = NULL,
hRequest = NULL;
// obtain a session handle.
hSession = WinHttpOpen( L"WinHTTP Example/1.0",
WINHTTP_ACCESS_TYPE_DEFAULT_PROXY,
WINHTTP_NO_PROXY_NAME,
WINHTTP_NO_PROXY_BYPASS, 0);
// Specify an HTTP server.
if (hSession)
hConnect = WinHttpConnect( hSession, L"www.myservarname.it",
INTERNET_DEFAULT_HTTPS_PORT, 0);
// Create an HTTP request handle.
if (hConnect)
hRequest = WinHttpOpenRequest( hConnect,
L"POST",
L"/rs/find.asp", NULL,
WINHTTP_NO_REFERER,
WINHTTP_DEFAULT_ACCEPT_TYPES,
0);
bResults=WinHttpAddRequestHeaders(hRequest,
L"Content-Type:
application/x-www-form-urlencoded\r\n\r\n",
-1L, WINHTTP_ADDREQ_FLAG_ADD);
// Send a request.
if (hRequest)
bResults =WinHttpSendRequest(hRequest,
WINHTTP_NO_ADDITIONAL_HEADERS , 0,
"CS=friuli", 18, 18,
0);
// End the request.
if (bResults)
bResults = WinHttpReceiveResponse( hRequest, NULL);
// Keep checking for data until there is nothing left.
if (bResults)
do
{
// Check for available data.
dwSize = 0;
if (!WinHttpQueryDataAvailable( hRequest, &dwSize))
printf("Error %u in
WinHttpQueryDataAvailable.\n",GetLastError());
// Allocate space for the buffer.
pszOutBuffer = new char[dwSize+1];
if (!pszOutBuffer)
{
printf("Out of memory\n");
dwSize=0;
}
else
{
// Read the data.
ZeroMemory(pszOutBuffer, dwSize+1);
if (!WinHttpReadData( hRequest, (LPVOID)pszOutBuffer,
dwSize, &dwDownloaded))
printf("Error %u in WinHttpReadData.\n",
GetLastError());
else
printf("%s", pszOutBuffer);
// Free the memory allocated to the buffer.
delete [] pszOutBuffer;
}
} while (dwSize>0);
// Report any errors.
if (!bResults)
printf("Error %d has occurred.\n",GetLastError());
// Close any open handles.
if (hRequest) WinHttpCloseHandle(hRequest);
if (hConnect) WinHttpCloseHandle(hConnect);
if (hSession) WinHttpCloseHandle(hSession);
return 1;
I think the problem is the WinHttpSendRequest call:
> // Send a request.
> if (hRequest)
> bResults =WinHttpSendRequest(hRequest,
> WINHTTP_NO_ADDITIONAL_HEADERS , 0,
> "CS=friuli", 18, 18,
> 0);
This code is posting a 9 byte string, but specifies that the length is 18
bytes. It should use 9 instead, as the payload is a 9-byte ANSI string, not
a wide-character Unicode string. Sending the string as single-byte ANSI is
the correct thing to do. The dwOptionalLength and dwTotalLength parameters
must specify the length of the data in bytes.
WinHTTP will use the dwTotalLength parameter to generate the Content-Length
header. So the server is expecting 18 bytes of data, and this would cause
the timeout error.
Also, when calling the WinHttpAddRequestHeaders function, you do not need
the \r\n characters at the end of the string, so the following is
sufficient:
bResults=WinHttpAddRequestHeaders(hRequest,
L"Content-Type: application/x-www-form-urlencoded",
-1L, WINHTTP_ADDREQ_FLAG_ADD);
Hope that helps.
Regards,
Stephen Sulzer
Microsoft Corporation
This posting is provided "AS IS" with no warranties, and confers no rights.
"Gigino" <realth...@yahoo.it> wrote in message
news:18b07ef0.02111...@posting.google.com...
I've copied the calls from this functions changing only the parts
relating to sync/async and the callback function, but i got error 4317
(ERROR_INVALID_OPERATION) in the WinHttpReceiveResponse call (the
WinHttpSendRequest returns 1...)
I really don't understand why this one works and the other example
doesn't...
thanks
Gigino
"Stephen Sulzer [Microsoft]" <ssu...@online.microsoft.com> wrote in message news:<eOcGReciCHA.2380@tkmsftngp09>...
"Stephen Sulzer [Microsoft]" <ssu...@online.microsoft.com> wrote in message news:<eOcGReciCHA.2380@tkmsftngp09>...