InternetReadFile问题(错误87 - 参数不正确)

时间:2009-02-06 19:56:17

标签: c++ winapi wininet

我在这里遇到InternetReadFile的问题,如果我在没有代理的计算机上运行应用程序,应用运行正常,但如果我尝试使用代理的计算机,我收到错误87(参数不正确)

这是我的代码:

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 
} 

我也尝试使用:

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

但也没有成功。

任何人都知道我做错了什么?

thankz, 埃里克

2 个答案:

答案 0 :(得分:1)

你需要继续调用InternetReadFile,直到它返回TRUE并且读取的字节数为0.这通常意味着至少有2次调用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.
}

答案 1 :(得分:0)

应该是:

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.
}
相关问题