我有这个VBScript
发送HTTP POST
请求并读取返回HTML
响应的简单方法。
Function httpPOST(url, body, username, password )
Set Http = CreateObject("Msxml2.ServerXMLHTTP")
Http.Open "POST", url, False, username, password
Http.setRequestHeader _
"Content-Type", _
"application/x-www-form-urlencoded"
Http.send body
pagestatus = Http.status
if pagestatus<> "200" then
httpPOST="Error:"& pagestatus
else
'httpPOST = Http.ResponseBody
'httpPOST = Http.responseText
Set objXMLDoc = CreateObject("MSXML.DOMDocument")
objXMLDoc.async = False
objXMLDoc.validateOnParse = False
objXMLDoc.load(Http.ResponseBody)
Set objNode = objXMLDoc.selectSingleNode("/html/body/center/img")
httpPost = objNode.getAttribute("alt")
end if
End Function
HTML
响应格式如下:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>---</title>
</head>
<body>
<center>
<img alt="You are now connected" src="pages/GEN/connected_gen.png">
</center>
</body>
</html>
这个脚本的问题是它总是返回Error: Object required: 'objNode'
我尝试了很多XML
解析器的变体,最后每次遇到与XML
对象相关的相同错误时都放弃了。