KamilG
KamilG

Reputation: 71

VBA WinHttpRequest 5.1 response text not full

Currently I am working on pulling data from webapplication using WinHttpRequest. I managed to succesfully perform various task, however I stumbled across weird problem. Some data is missing in .ResponseText. I've done the task manually and the responsebody is:

   <?xml version="1.0" encoding="UTF-8"?>
 <mxRoot><rows><r ra="t" o="20336.41905.48904.52482" p="" id="0,0" level="0" filter="false" t="1515418285649" r="" d="" hc="">
 <c a="91664964" i="images/iconSmallPart.png">91664964</c><c a="001">001</c> :ConfidentialInformations: </rows>

And when I do the same with VBA the answer is shorter:

 <?xml version="1.0" encoding="UTF-8"?>
 <mxRoot><rows><r ra="t" o="20336.41905.39945.55654" p="" id="0,0" level="0" filter="false" /></rows>

It is like I am missing some depth from the response. Below code I am using.

Set MyRequest = CreateObject("WinHTTP.WinHTTPrequest.5.1")

MyRequest.Open "POST", URL

MyRequest.SetRequestHeader "Host", "plmprod.pg.com"
MyRequest.Option(WinHttpRequestOption_EnableRedirects) = False
MyRequest.SetRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 6.1; rv:57.0) Gecko/20100101 Firefox/57.0"
MyRequest.SetRequestHeader "Accept", "*/*"
MyRequest.SetRequestHeader "Accept-Language", "pl,en-US;q=0.7,en;q=0.3"
MyRequest.SetRequestHeader "Accept-Encoding", "gzip, deflate, br"
MyRequest.SetRequestHeader "Referer", "RefererURL"
MyRequest.SetRequestHeader "Content-Type", "undefined"
MyRequest.SetRequestHeader "charset", "UTF-8"
MyRequest.SetRequestHeader "csrfTokenName", "ENO_CSRF_TOKEN"
MyRequest.SetRequestHeader "ENO_CSRF_TOKEN", CSRFTOKEN
MyRequest.SetRequestHeader "Cookie", "testcookie=1; " & JSESSION & "; " & SERVERID
MyRequest.SetRequestHeader "Connection", "keep-alive"
MyRequest.SetRequestHeader "Content-Length", "0"
MyRequest.Send
MyRequest.WaitForResponse
Debug.Print MyRequest.ResponseText

Does anyone know what the issue is? Even though I found similar topics, there is no clear answer.

Upvotes: 1

Views: 2772

Answers (1)

S Meaden
S Meaden

Reputation: 8260

Browsing that type library there are some events to trap, OnResponseDataAvavilable , OnResponseStart, OnResponseFinished. Try these to see if they handle your chunking.

Some skeleton code, your request variable needs to be defined in a class module for the WithEvents keyword to compile

Option Explicit

Private WithEvents oReq As WinHttp.WinHttpRequest

Private Sub oReq_OnResponseDataAvailable(Data() As Byte)

    Dim sThisChunk As String
    sThisChunk = StrConv(Data(), vbUnicode)

End Sub

Private Sub oReq_OnResponseFinished()

End Sub

Private Sub oReq_OnResponseStart(ByVal Status As Long, ByVal ContentType As String)

End Sub

Upvotes: 1

Related Questions