vba下,xmlhttp和inet都无法post,代码已给出,
Part 1. 用抓包器在IE界面下手动填写数据后提交所抓取的数据:POST /domain/bulkregister_submit.php HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Referer: http://www.now.cn/domain/bulkregister.php
Accept-Language: zh-cn
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip, deflate
Host: www.now.cn
Content-Length: 83
Connection: Keep-Alive
Cache-Control: no-cache
Cookie: PHPSESSID=9m8vnfp3n990ioun8s8bt1jpm7
domainToCheck=123456&picCode=3228&Submit=+++%C5%FA%C1%BF%B2%E9%D1%AF&suffix%5B%5D=.cn
Part 2. 使用xmlhttp post
postdata = "domainToCheck=123456&Submit=+++%C5%FA%C1%BF%B2%E9%D1%AF&suffix%5B%5D=.cn&picCode=" & piccode
getcookie=userform1.webbrowser1.document.cookie '我是在vba环境下,webbrowser控件是加在userform下的,所以这里前面有个 userform1.
With xmlhttp
.Open "POST", "http://www.now.cn/domain/bulkregister.php", False
.setrequestheader "Accept", "text/html, application/xhtml+xml, */*"
.setrequestheader "Referer", "http://www.now.cn/domain/bulkregister.php"
.setrequestheader "Accept-Language", "zh-cn"
.setrequestheader "User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)"
.setrequestheader "Content-Type", "application/x-www-form-urlencoded"
.setrequestheader "Accept-Encoding", "gzip, deflate"
.setrequestheader "host", "www.now.cn"
.setrequestheader "Content-Length", Len(postdata)
.setrequestheader "Connection", "Keep-Alive"
.setrequestheader "Cache-Control", "no-cache"
.setrequestheader "cookie", Getcookie
.send (postdata)
Do Until .ReadyState = 4
DoEvents
Loop
End With
POST不成功,然后找了很多地方,貌似有个说法,就是 xmlhttp无法提交 referer ,原因是为了防止欺骗.
罢了,如果的确不行,我就放弃这个方法.
到底能提交吗?
Part 3,用 inet提交
strURL = "http://www.now.cn/domain/bulkregister.php"
strSendHeader = "Content-Type:application/x-www-form-urlencoded"
UserForm1.Inet1.Execute strURL, "POST", postData, strSendHeader '我是在vba环境下,所以控件是加在userform上的,所以 inet1前面有个 userform1, 否则无法调用。
Do Until UserForm1.Inet1.StillExecuting = False
DoEvents
Loop
错误提示: 不能易做图的类型. 然后按F1查原因,原始代码是:
icUnsupportedType , 35760 ,“不能强制类型”
--------------------编程问答-------------------- 在 xmlhttp下提交,我是先用 webbrowser 请求一下网页,并把验证码图片用复制的方式取走,通过验证码分析dll文件取得验证码字符 ,然后记录下请求此验证码时产生的 cookie ,再用xmlhttp提交,匹配上cookie和验证码,这些都没问题,就是无法提交成功。
在 inet下,好像是类型不匹配,到底是怎么回事呢。我的 strURL , postData, strSendHeader 这3个变量都是在前面声明过了,都是 string 。
--------------------编程问答-------------------- 用xmlhttp post后,抓取的数据:
POST /domain/bulkregister.php HTTP/1.1
Accept: text/html, application/xhtml+xml, */*
Cookie: PHPSESSID=0279d6tk8ta3p5vh1k3bks7c22
Connection: Keep-Alive
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0; Trident/5.0)
Cache-Control: no-cache
Content-Type: application/x-www-form-urlencoded
Accept-Language: zh-cn
Accept-Encoding: gzip, deflate
Host: www.now.cn
Content-Length: 85
domainToCheck=123456&Submit=+++%C5%FA%C1%BF%B2%E9%D1%AF&suffix%5B%5D=.cn&picCode=2061
没cookie和referer.
--------------------编程问答-------------------- 上面说错了,有cookie ..没referer.
我前后帖的二次cookie不一样,是因为是单独的二次测试, 在一次里是一样的..
补充:VB , 网络编程