BQYAHOO BUG 3

终于弄明白函数InternetOpenUrl 和InternetReadFile 的使用方法。

昨天,和一个网上的朋友测试BQYAHOO 。
InternetReadFile 只能读取网页的前半部分,后半部分没有,这样也就无法进行网页分析。
我想当然的认为:他的网速太慢,跟不上程序的节奏。
当时,他就提醒我说:他的网速并不慢。

后来我知道自己错了。

下班后,我偷偷地使用部门的服务器进行测试。
目前,员工的机器都必须使用代理才能访问外网,出于限制上网的考虑。
这台服务器可以直接访问外网,而且速度很快,实际上,这台服务器用来给外网的客户访问,不过,访问量小的可怜。

这台服务器访问雅虎信箱,速度很快,可以达到每秒200K 。
就是在这种速度下,InternetReadFile 仍然只能读取网页的前半部分。
我当时明白了,出现这种情况,不是网络速度太慢,而是太快了。

仔细查找msdn,得到下面这一段话:
InternetReadFile operates much like the base ReadFile function, with a few exceptions. Typically, InternetReadFile retrieves data from an HINTERNET handle as a sequential stream of bytes. The amount of data to be read for each call to InternetReadFile is specified by the dwNumberOfBytesToRead parameter and the data is returned in the lpBuffer parameter. A normal read retrieves the specified dwNumberOfBytesToRead for each call to InternetReadFile until the end of the file is reached. To ensure all data is retrieved, an application must continue to call the InternetReadFile function until the function returns TRUE and the lpdwNumberOfBytesRead parameter equals zero. This is especially important if the requested data is written to the cache, because otherwise the cache will not be properly updated and the file downloaded will not be committed to the cache. Note that caching happens automatically unless the original request to open the data stream set the INTERNET_FLAG_NO_CACHE_WRITE flag.

When an application retrieves a handle using InternetOpenUrl, WinINet attempts to make all data look like a file download, in an effort to make reading from the Internet easier for the application. For some types of information, such as FTP file directory listings and Gopher directory listings, it converts the data to be returned by InternetReadFile to an HTML stream. It does this on a line-by-line basis. For example, it can convert an FTP directory listing to a line of HTML and return this HTML to the application.

WinINet attempts to write the HTML to the lpBuffer buffer a line at a time. If the application's buffer is too small to fit at least one line of generated HTML, the error code ERROR_INSUFFICIENT_BUFFER is returned as an indication to the application that it needs a larger buffer. Also, converted lines might not completely fill the buffer, so InternetReadFile can return with less data in lpBuffer than requested. Subsequent reads will retrieve all the converted HTML. The application must again check that all data is retrieved as described previously.

在这段话的指引下,我终于把InternetOpenUrl 和InternetReadFile使用正确了。

只读取半个页面的历史终于一去不复返了!

大约晚上八点的时候,我在部门这台可以直接访问外网的机器上测试BQYAHOO成功了。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值