vb XMLHTTP post 问题。
FunctionXMLHttpPOST(ByValurlAsString,ByValPostDataAsString)AsStringSetXML=CreateObjec...
Function XMLHttpPOST(ByVal url As String, ByVal PostData As String) As String
Set XML = CreateObject("Microsoft.XMLHTTP")
With XML
.Open "POST", url, False
.setRequestHeader "Accept", "*/*"
.setRequestHeader "Accept-Language", "zh-cn"
.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Referer", ""
.setRequestHeader "Content-Length", Len(PostData)
.setRequestHeader "Connection", "Keep-Alive"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Referer", "http://www.haedu.gov.cn/hadoe_plus/gk_cx/queryresult_iframe.aspx"
.Send (PostData)
Do Until .ReadyState = 4
DoEvents
Loop
XMLHttpPOST = .responseText
End With
Set XML = Nothing
End Function
Private Sub C1_Click()
Text1.Text = XMLHttpPOST("http://www.heao.gov.cn/PZQuery/PZLQueryResult.aspx", "ksh=13411101151089&bmxh=110111150009&sfzh=33333&Submit.x=46&Submit.y=11&Submit=%E6%8F%90%E4%BA%A4")
帮我测试一下这个代码怎么回事?为什么拒绝访问。
End Sub 展开
Set XML = CreateObject("Microsoft.XMLHTTP")
With XML
.Open "POST", url, False
.setRequestHeader "Accept", "*/*"
.setRequestHeader "Accept-Language", "zh-cn"
.setRequestHeader "User-Agent", "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0)"
.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
.setRequestHeader "Referer", ""
.setRequestHeader "Content-Length", Len(PostData)
.setRequestHeader "Connection", "Keep-Alive"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Referer", "http://www.haedu.gov.cn/hadoe_plus/gk_cx/queryresult_iframe.aspx"
.Send (PostData)
Do Until .ReadyState = 4
DoEvents
Loop
XMLHttpPOST = .responseText
End With
Set XML = Nothing
End Function
Private Sub C1_Click()
Text1.Text = XMLHttpPOST("http://www.heao.gov.cn/PZQuery/PZLQueryResult.aspx", "ksh=13411101151089&bmxh=110111150009&sfzh=33333&Submit.x=46&Submit.y=11&Submit=%E6%8F%90%E4%BA%A4")
帮我测试一下这个代码怎么回事?为什么拒绝访问。
End Sub 展开
2个回答
展开全部
可以用WEBBROWSER 控件操作,有些需要登录验证的网站用XMLHTTP不如用WEBBROWSER操作简单.何况他的参数不能直接带在提交URL之后,我查看了,他还有两个隐藏INPUT(__VIEWSTATE/__EVENTVALIDATION),有COOKIE,查看到他的头:
Cache-Control: private
Date: Sun, 03 Aug 2014 10:26:33 GMT
Content-Length: 2689
Content-Type: text/html; charset=gb2312
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=r4vqgeuxilexen451qa3fqzv; path=/; HttpOnly
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
X-UA-Compatible: IE=5.5
Cache-Control: private
Date: Sun, 03 Aug 2014 10:26:33 GMT
Content-Length: 2689
Content-Type: text/html; charset=gb2312
Server: Microsoft-IIS/7.5
Set-Cookie: ASP.NET_SessionId=r4vqgeuxilexen451qa3fqzv; path=/; HttpOnly
X-AspNet-Version: 2.0.50727
X-Powered-By: ASP.NET
X-UA-Compatible: IE=5.5
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询