WinHTTPRequest.ResponseText 未返回完整的 HTML?

发布于 2024-11-16 03:57:19 字数 498 浏览 2 评论 0原文

我尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

橘和柠 2024-11-23 03:57:19

我已经有一段时间没有使用WinHttpRequest了,但我相信只要你读到ResponseText,WinHttpRequest就会放弃处理响应。由于您正在认真阅读响应,我猜当您打印 ResponseText 时,完整的响应尚未到达!

我认为您有 2 个选项可以尝试:

  1. 使用 WinHttpRequest.WaitForResponse() 等待整个响应准备好
  2. 使用 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:

  1. Use WinHttpRequest.WaitForResponse() to wait for the entire response to be ready
  2. Use WinHttpRequest.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文