开发者

WinHTTPRequest.ResponseText not returning the full HTML?

开发者 https://www.devze.com 2023-03-13 21:47 出处:网络
I tried to use WinHTTP Request to retrieve a webpage (HTTPS website) in VB.Net and for som开发者_运维问答e reason it was only returning the partial HTML, is there any length restriction on the number

I tried to use WinHTTP Request to retrieve a webpage (HTTPS website) in VB.Net and for som开发者_运维问答e 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消