【问题标题】:InternetReadFile Problem (error 87 - The parameter is incorrect)InternetReadFile 问题(错误 87 - 参数不正确)
【发布时间】:2009-02-06 19:56:16
【问题描述】:

我在使用 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); 

但也没有成功。

有人知道我做错了什么吗?

谢谢, 埃里克

【问题讨论】:

    标签: c++ winapi wininet


    【解决方案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.
    }
    

    【讨论】:

      【解决方案2】:

      应该是:

      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.
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-04-20
        • 1970-01-01
        • 2012-04-07
        • 2020-04-08
        • 2021-06-28
        • 2011-10-21
        • 1970-01-01
        相关资源
        最近更新 更多