MSXML2.ServerXMLHTTP responseText 获取的内容不完整,解决方案

今天无意发现一个问题, 有个别几个网页使用 MSXML2.ServerXMLHTTP 获取网页源代码的时候,.responseText 总是返回一部分内容,无法获取完整的内容。

经过搜索,找到解决方案: 使用 .responseBody (参考: http://blog.links.cn/asp/aspxmlhttp.html)

不过从参考的文章上看,他的问题与我不完全一样,我测试的时候,只需将 responseText 替换成 responseBody,问题就解决了

参考文章中还提到 adodb.stream的一个BUG,需要将 chr(0) 替换成 ""

'httpGet = xmlhttp.responseText
httpGet = replace(BytesToBstr(xmlhttp.responseBody, "utf-8"), chr(0), "")

'字节根据指定编码转换成字符
Function BytesToBstr(Body,Cset)
Dim Objstream
Set Objstream = Server.CreateObject("adodb.stream")
objstream.Type = 1
objstream.Mode =3
objstream.Open
objstream.Write Body
objstream.Position = 0
objstream.Type = 2
objstream.Charset = Cset
BytesToBstr = objstream.ReadText
objstream.Close
set objstream = nothing
End Function

原文地址:https://www.cnblogs.com/personnel/p/4747697.html