注册 登录
就爱编程论坛 返回首页

晴云孤魂的个人空间 http://bbs.waibc.com/?1 [收藏] [复制] [分享] [RSS]

日志

VBS发送带Cookie的HTTP请求

已有 349 次阅读2012-1-12 14:40 |个人分类:资料收藏夹|

在昨天的《使用正确版本的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", "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的网页就不用愁了。


路过

鸡蛋

鲜花

握手

雷人
收藏 分享 分享到人人 转发到微博 举报

发表评论 评论 (1 个评论)

回复 admin 2012-4-10 00:38
  

facelist

您需要登录后才可以评论 登录 | 注册
验证问答 换一个 验证码 换一个

晴云孤魂's Blog|就爱编程搜帖|手机版|Archiver|就爱编程论坛     

GMT+8, 2025-7-2 01:16 , Processed in 0.171659 second(s), 26 queries .

Powered by Discuz! X2

© 2001-2011 Comsenz Inc.

回顶部