views:

915

answers:

2

Hello,

I have a problem here with InternetReadFile, if I run the application in a computer without proxy, the app runs ok, but if I try to use with a computer using proxy, I receive an error 87 (The parameter is incorrect).

Thats my code:

conHandle = InternetOpen("Test", INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); 
... 
hFile = InternetOpenUrl(conHandle, url.c_str(), NULL, 0, INTERNET_FLAG_RELOAD, 0);  
... 

if (!InternetReadFile(hFile, buffer, maxBufferSize, &size)) 
{ 
    // error 
}

And I also tried to use:

InternetOpen("Test", INTERNET_OPEN_TYPE_PROXY, "proxystr", NULL, 0);

but without success too.

Anyone knows anything about what Im doing wrong?

thankz, erick

+1  A: 

You need to keep calling InternetReadFile in a loop until it returns TRUE and the number of bytes read is 0. This usually means at least 2 calls to InternetReadFile.

while ( InternetReadFile( hFile, buffer, maxBufferSize, &size ) == FALSE || size > 0 )
{
   // process buffer contents.
   // for ex: write the contents of buffer to a temp file for example.
}
Srikumar
A: 

It should be while ( InternetReadFile( hFile, buffer, maxBufferSize, &size ) == TRUE || size > 0 ) { // process buffer contents. // for ex: write the contents of buffer to a temp file for example. }

Sumedh