WinHTTPRequest.ResponseText 未返回完整的 HTML?
我尝试使用 WinHTTP Request 在 VB.Net 中检索网页(HTTPS 网站),但由于某种原因它只返回部分 HTML,它可以接受的字符数是否有长度限制?如果是这样,我可以获取第 10000 个字符之后的内容吗?
相关代码在这里:
oRequest = New WinHttp.WinHttpRequest oRequest.Open("GET", sQueryURL, False) oRequest.SetTimeouts(0, 600000, 0, 0) oRequest.Send() If oRequest.Status = "200" Then Debug.Print(oRequest.ResponseText) Else End If
I tried to use WinHTTP Request to retrieve a webpage (HTTPS website) in VB.Net and for some reason it was only returning the partial HTML, is there any length restriction on the number of characters it could take? If so, can I get the content after, say, 10000th character?
The relevant code is here:
oRequest = New WinHttp.WinHttpRequest oRequest.Open("GET", sQueryURL, False) oRequest.SetTimeouts(0, 600000, 0, 0) oRequest.Send() If oRequest.Status = "200" Then Debug.Print(oRequest.ResponseText) Else End If
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经有一段时间没有使用WinHttpRequest了,但我相信只要你读到ResponseText,WinHttpRequest就会放弃处理响应。由于您正在认真阅读响应,我猜当您打印 ResponseText 时,完整的响应尚未到达!
我认为您有 2 个选项可以尝试:
WinHttpRequest.WaitForResponse()
等待整个响应准备好WinHttpRequest.ResponseStream
分块处理响应(您需要将块从字节转换为可读文本)我无法判断您是否使用 VB.Net,但如果您是:请考虑使用 System.Web.HttpRequest。界面几乎相同,您将可以更轻松地找到工作示例和建议。
It's been a while since I've used WinHttpRequest, but I believe as soon as you read ResponseText, WinHttpRequest will abandon processing the response. Since you're diving right in reading the response I'd guess the full response hasn't arrived by the time you print ResponseText!
I think you have 2 options to try:
WinHttpRequest.WaitForResponse()
to wait for the entire response to be readyWinHttpRequest.ResponseStream
to process the response in chunks (you'll need to convert the chunks from bytes to readable text)I can't tell if you're using VB.Net, but if you are: consider using System.Web.HttpRequest. The interface is pretty much the same and you will have an easier time finding working examples and advice.