VBS发送带Cookie的HTTP请求

标签: , , ,

在昨天的《使用正确版本的XMLHTTP》中卖了个关子,ServerXMLHTTP的功能比XMLHTTP强大,你现在大概已经猜到了吧。没错,用ServerXMLHTTP可以在HTTP请求头中加入Cookie,而XMLHTTP不可以。

为了方便测试,先写一个回显Cookie的简单的PHP程序:

<?php
foreach($_COOKIE as $key => $value)
    echo "$key => $value\r\n";
?>

然后分别用ServerXMLHTTP和XMLHTTP测试:

Dim http
Set http = CreateObject("Msxml2.XMLHTTP")
http.open "GET", "https://demon.tw/test/cookie.php", False
http.SetRequestHeader "Cookie", "user=demon; passwd=123456"
http.send
WScript.Echo http.responseText

用Msxml2.XMLHTTP什么都没有返回。

Dim http
Set http = CreateObject("Msxml2.ServerXMLHTTP")
http.open "GET", "https://demon.tw/test/cookie.php", False
http.SetRequestHeader "Cookie", "user=demon; passwd=123456"
http.send
WScript.Echo http.responseText

用Msxml2.ServerXMLHTTP返回

user => demon

passwd => 123456

以后碰到需要Cookie的网页就不用愁了。

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. 通过SSH访问iPad
  2. VBS也玩验证码识别
  3. md5sum for windows
  4. Windows 7 快速共享Internet无线网络
  5. VBS调用WMI搜索文件

4 条评论 发表在“VBS发送带Cookie的HTTP请求”上

  1. luguo说道:

    很有用,谢了。

  2. jack说道:

    首先对于作者所说的这一点我提出一下我的质疑,因为经过我的初步实践发现,XMLHTTP对象和ServerXMLHTTP对象都可以在HTTP请求头中加入Cookie信息,而且服务器端也能收到这个HTTP请求中的Cookie信息,完成相同的处理,我不知道这个会不会跟相应的服务器或者本地设置有关系,我本地用的是Winxp+IE7,服务器用的是Linux red hat+Weblogic

  3. caesar说道:

    那怎么使用post呢?

  4. 9wea说道:

    如何用vbs获取cookie??@Demon

留下回复