Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

InternetReadFile vs. InternetReadFileEx

349 views
Skip to first unread message

David G.

unread,
Aug 28, 2001, 5:30:00 PM8/28/01
to
Are there any advantages to using Ex for synchronous requests? Also, can
someone post some sample code for using Ex? Thanks.


Brian Combs

unread,
Sep 10, 2001, 2:36:32 PM9/10/01
to
Hello
Most folks just use InternetReadFile over InternetReadFileEx to read the
return data from a request because it is easier to use. There is not really
any advantage to using either one, they will both read the return data from
the request.

The following example shows reading the return data with InternetReadFile
// **** Start Code ****
#include <windows.h>
#include <wininet.h>
#include <iostream.h>

void main(void)
{

HINTERNET hInternet,hConnect, hRequest;

hInternet = InternetOpen("TestApp", INTERNET_OPEN_TYPE_PRECONFIG, NULL,
NULL, 0);

if(!(hConnect = InternetConnect(hInternet, "YourServer",
INTERNET_INVALID_PORT_NUMBER,
NULL, NULL, INTERNET_SERVICE_HTTP, 0,0)))
{
cout << "internet open error: " << GetLastError();
return;
}

if(!(hRequest = HttpOpenRequest(hConnect, "GET", "/VirtualDir/hello.htm",
"HTTP/1.1", NULL,
NULL, INTERNET_FLAG_NO_CACHE_WRITE|INTERNET_FLAG_RELOAD, 0)))
{
cout << "HttpOpenRequest error: " << GetLastError();
return;
}

if (!HttpSendRequest(hRequest, NULL, NULL,NULL, 0))
{
cout << "HttpSendRequest error: " << GetLastError();
return;
}

char checkHeaders[1024];
DWORD hlength = 1024;
if(!HttpQueryInfo(hRequest,HTTP_QUERY_RAW_HEADERS_CRLF, checkHeaders,
&hlength, NULL))
{
cout << "HttpQueryInfo error: " << GetLastError();
return;
}
cout << checkHeaders << endl;

INTERNET_BUFFERS InetBuffers;
TCHAR Data[1024] = "\0";
DWORD DataLength = 1024;
InetBuffers.dwStructSize = sizeof(INTERNET_BUFFERS);
InetBuffers.lpvBuffer = Data;
InetBuffers.dwBufferLength = DataLength;

if(!InternetReadFileEx(hRequest, &InetBuffers,IRF_SYNC , 0))
cout<< "InternetReadFileEx failed " <<GetLastError() << endl;
else
cout << (char*)InetBuffers.lpvBuffer << endl;

}
// **** End Code ****

Thanks
Brian
Microsoft Developer Support
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2001 Microsoft Corporation. All rights
reserved.

0 new messages