您的位置:首页 > 理论基础 > 计算机网络

用VBS实现的发送带Cookie的HTTP请求的代码

2018-10-12 14:10 465 查看
为了方便测试,先写一个回显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", "http://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", "http://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的网页就不用愁了。
原文: http://demon.tw/programming/vbs-http-cookie.html

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: