Board index » cppbuilder » Problems with HttpSendRequestEx

Problems with HttpSendRequestEx


2006-02-21 02:36:44 AM
cppbuilder71
I'm trying to use HttpSendRequestEx to make assynchronious http requests,
but all i'm getting is 0 bytes.If i use HttpSendRequest it works fine, but
i cannot
make it asynchroniuos, so it blocks my thread.
Internet = InternetOpen("App",INTERNET_OPEN_TYPE_PRECONFIG,NULL,
NULL,/*INTERNET_FLAG_ASYNC*/0);
Connection = InternetConnect(Internet,server,INTERNET_INVALID_PORT_NUMBER,
NULL,NULL,INTERNET_SERVICE_HTTP,0,NULL);
if(Connection)
{
Request =
HttpOpenRequest(Connection,"GET",script,NULL,HTTP_VERSION,NULL,
INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE,
NULL);
if(Request)
{
DWORD Size = 0;
DWORD Read = 0;
DWORD Total = 0;
result = HttpSendRequestEx(Request,NULL,NULL,HSR_DOWNLOAD,0);
/*result = HttpSendRequest(Request,NULL,0,NULL,0);*/
InternetQueryDataAvailable(Request,&Read,0,0);
printf("%d\n",Read);
InternetCloseHandle(Request);
}
InternetCloseHandle(Connection);
}
 
 

Re:Problems with HttpSendRequestEx

"Bogdan" < XXXX@XXXXX.COM >wrote in message
Quote
If i use HttpSendRequest it works fine, but I cannot make
it asynchroniuos, so it blocks my thread.
Your thread is being blocked anyway because your code is processing the
connection synchronously regardless of the flags you set.
InternetQueryDataAvailable() is a blocking function.
Quote
Request =
HttpOpenRequest(Connection, "GET", script, NULL,
HTTP_VERSION, NULL, INTERNET_FLAG_RELOAD |
INTERNET_FLAG_NO_CACHE_WRITE, NULL);
You have the lpszVersion and lpszReferer parameters reversed, and you are
passing NULL for the lpszAcceptTypes parameter. That last part in
particular is important. By passing NULL, you are telling the server that
your client cannot accept anything at all. At the very least, you should be
specifying "*/*".
Quote
result = HttpSendRequestEx(Request,NULL,NULL,HSR_DOWNLOAD,0);
The dwFlags parameter is reserved. It must be set to 0, not HSR_DOWNLOAD.
Gambit
 

Re:Problems with HttpSendRequestEx

Remy Lebeau (TeamB) wrote:
Quote
"Bogdan" wrote in message

>If i use HttpSendRequest it works fine,

>Request = HttpOpenRequest(Connection, "GET", script, NULL,

>result = HttpSendRequestEx(Request,NULL,NULL,HSR_DOWNLOAD,0);
>InternetQueryDataAvailable(Request,&Read,0,0);
In addition, this bit from MSDN might be a problem....
"For HINTERNET handles created by HttpOpenRequest and sent by
HttpSendRequestEx, a call to HttpEndRequest must be made on the handle
before InternetQueryDataAvailable can be used."
msdn.microsoft.com/library/default.asp=true
 

{smallsort}