VBA WinHttpRequest 5.1响应文本未满

时间:2018-01-08 13:42:17

标签: excel vba excel-vba winhttprequest

目前我正致力于使用WinHttpRequest从webapplication中提取数据。我设法成功完成了各种任务,但是偶然发现了一些奇怪的问题。 .ResponseText中缺少一些数据。我手动完成了任务,响应体是:

   <?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>

当我对VBA做同样的事情时答案更短:

 <?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>

就像我在回复中遗漏了一些深度。我正在使用的代码如下。

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

有谁知道这是什么问题?尽管我发现了类似的主题,但没有明确的答案。

1 个答案:

答案 0 :(得分:1)

浏览该类型库时,有一些事件要陷阱,on load completeon init completeOnResponseDataAvavilable。试试这些,看看它们是否能处理你的组块。

一些框架代码,您的请求变量需要在类模块中定义,以便OnResponseStart关键字进行编译

OnResponseFinished