MSXML2.XMLHTTP は仕様として自動的にクッキーが有効です
copy
' ***********************************************************
' クライアント用オブジェクト
' ***********************************************************
Set objHTTP = Wscript.CreateObject("MSXML2.XMLHTTP" )
' ***********************************************************
' クッキーが自動的に受け渡しされている事を確認するテスト
' ***********************************************************
Call objHTTP.Open("GET" ,"http://localhost/web/test/sv1.php" ,False)
Call objHTTP.Send("" )
' ***********************************************************
' 全てのヘッダ( クッキーが含まれる )
' ***********************************************************
strHeaders = objHTTP.getAllResponseHeaders()
Wscript.Echo strHeaders
' ***********************************************************
' このレスポンスにクッキーがセットされている事を確認
' ***********************************************************
Call objHTTP.Open("GET" ,"http://localhost/web/test/sv2.php" ,False)
Call objHTTP.Send("" )
Wscript.Echo objHTTP.responseText
sv1.php
copy
<?
setcookie( 'data' ,"1234" );
setcookie( 'lightbox' ,"winofsql" );
?>
OK
sv2.php
copy
------------------------------
<?
print $_SERVER['HTTP_COOKIE' ] . "\n" ;
?>
------------------------------
OK
copy
C:\user\web\test>cscript test1.vbs
Microsoft (R) Windows Script Host Version 5.7
Copyright (C) Microsoft Corporation 1996-2001. All rights reserved.
MIME-Version: 1.0
Server: AnWeb/1.42p
Date: Fri, 18 Jun 2010 01:56:01 GMT
Transfer-Encoding: chunked
Expires: -1
Pragma: no-cache
Cache-control: no-cache
Last-Modified: Fri, 18 Jun 2010 01:56:01 GMT
X-Powered-By: PHP/5.3.2
Set-Cookie: data=1234
Set-Cookie: lightbox=winofsql
Content-type: text/html
------------------------------
data=1234; lightbox=winofsql
------------------------------
同様の事を php の cURL でテストしました
copy
<?
// **********************************************************
// curl クッキーテスト
// **********************************************************
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
// *********************************************************
// curl 処理
// *********************************************************
$target_url = 'http://localhost/web/test/sv1.php' ;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $target_url);
// ***********************************************************
// クッキーが自動的に受け渡しされるようにする
// ***********************************************************
curl_setopt($curl, CURLOPT_COOKIEFILE, 'c:\\cookiefile.txt' );
curl_setopt($curl, CURLOPT_COOKIEJAR, 'c:\\cookiefile.txt' );
// *********************************************************
// 送信( 一回目 )
// *********************************************************
curl_setopt($curl, CURLOPT_VERBOSE, true); // デバッグ
$handle_1 = fopen("./debug1.txt" , "w" );
curl_setopt($curl, CURLOPT_STDERR, $handle_1);
$handle_2 = fopen("./ret_header1.txt" , "w" );
curl_setopt($curl, CURLOPT_WRITEHEADER, $handle_2);
$result = curl_exec($curl);
fclose($handle_2);
fclose($handle_1);
print $result;
// *********************************************************
// curl 処理
// *********************************************************
$target_url = 'http://localhost/web/test/sv2.php' ;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $target_url);
// ***********************************************************
// クッキーが自動的に受け渡しされるようにする
// ***********************************************************
curl_setopt($curl, CURLOPT_COOKIEFILE, 'c:\\cookiefile.txt' );
curl_setopt($curl, CURLOPT_COOKIEJAR, 'c:\\cookiefile.txt' );
// *********************************************************
// 送信( 二回目 )
// *********************************************************
curl_setopt($curl, CURLOPT_VERBOSE, true); // デバッグ
$handle_a = fopen("./debug2.txt" , "w" );
curl_setopt($curl, CURLOPT_STDERR, $handle_a);
$handle_b = fopen("./ret_header2.txt" , "w" );
curl_setopt($curl, CURLOPT_WRITEHEADER, $handle_b);
$result = curl_exec($curl);
print $result;
fclose($handle_b);
fclose($handle_a);
// *********************************************************
// curl 終了
// *********************************************************
curl_close($curl);
?>
dubug1.txt
copy
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /web/test/sv1.php HTTP/1.1
Host: localhost
Accept: */*
< HTTP/1.1 200 Document follows
< MIME-Version: 1.0
< Server: AnWeb/1.42p
< Date: Fri, 18 Jun 2010 02:00:40 GMT
< Transfer-Encoding: chunked
< Expires: -1
< Pragma: no-cache
< Cache-control: no-cache
< Last-Modified: Fri, 18 Jun 2010 02:00:40 GMT
< X-Powered-By: PHP/5.3.2
* Added cookie data="1234" for domain localhost, path /web/test/, expire 0
< Set-Cookie: data=1234
* Added cookie lightbox="winofsql" for domain localhost, path /web/test/, expire 0
< Set-Cookie: lightbox=winofsql
< Content-type: text/html
<
* Connection #0 to host localhost left intact
* Closing connection #0
dubug2.txt
copy
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /web/test/sv2.php HTTP/1.1
Host: localhost
Accept: */*
Cookie: data=1234; lightbox=winofsql
< HTTP/1.1 200 Document follows
< MIME-Version: 1.0
< Server: AnWeb/1.42p
< Date: Fri, 18 Jun 2010 02:00:41 GMT
< Transfer-Encoding: chunked
< Expires: -1
< Pragma: no-cache
< Cache-control: no-cache
< Last-Modified: Fri, 18 Jun 2010 02:00:41 GMT
< X-Powered-By: PHP/5.3.2
< Content-type: text/html
<
* Connection #0 to host localhost left intact
* Closing connection #0
cookiefile.txt
copy
# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.
localhost FALSE /web/test/ FALSE 0 data 1234
localhost FALSE /web/test/ FALSE 0 lightbox winofsql
copy
<?
setcookie( 'data' ,"1234" );
setcookie( 'lightbox' ,"winofsql" );
header( "Location: http://localhost/web/test/sv2.php" );
?>
OK
copy
<?
// **********************************************************
// curl クッキーテスト
// **********************************************************
header( "Content-Type: text/html; Charset=utf-8" );
header( "pragma: no-cache" );
header( "Expires: Wed, 31 May 2000 14:59:58 GMT" );
header( "Cache-control: no-cache" );
// *********************************************************
// curl 処理
// *********************************************************
$target_url = 'http://localhost/web/test/sv1.php' ;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_BINARYTRANSFER, true);
curl_setopt($curl, CURLOPT_URL, $target_url);
// ***********************************************************
// クッキーが自動的に受け渡しされるようにする
// ***********************************************************
curl_setopt($curl, CURLOPT_COOKIEFILE, 'c:\\cookiefile.txt' );
curl_setopt($curl, CURLOPT_COOKIEJAR, 'c:\\cookiefile.txt' );
curl_setopt($curl, CURLOPT_MAXREDIRS , 10);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION , true);
// *********************************************************
// 送信( 一回目 )
// *********************************************************
curl_setopt($curl, CURLOPT_VERBOSE, true); // デバッグ
$handle_1 = fopen("./debug1.txt" , "w" );
curl_setopt($curl, CURLOPT_STDERR, $handle_1);
$handle_2 = fopen("./ret_header1.txt" , "w" );
curl_setopt($curl, CURLOPT_WRITEHEADER, $handle_2);
$result = curl_exec($curl);
fclose($handle_2);
fclose($handle_1);
print $result;
// *********************************************************
// curl 終了
// *********************************************************
curl_close($curl);
?>
copy
* About to connect() to localhost port 80 (#0)
* Trying 127.0.0.1... * connected
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /web/test/sv1.php HTTP/1.1
Host: localhost
Accept: */*
< HTTP/1.1 302 Moved Temporarily
< MIME-Version: 1.0
< Server: AnWeb/1.42p
< Date: Fri, 18 Jun 2010 02:35:30 GMT
< Transfer-Encoding: chunked
< Expires: -1
< Pragma: no-cache
< Cache-control: no-cache
< Last-Modified: Fri, 18 Jun 2010 02:35:30 GMT
< X-Powered-By: PHP/5.3.2
* Added cookie data="1234" for domain localhost, path /web/test/, expire 0
< Set-Cookie: data=1234
* Added cookie lightbox="winofsql" for domain localhost, path /web/test/, expire 0
< Set-Cookie: lightbox=winofsql
< Location: http://localhost/web/test/sv2.php
< Content-type: text/html
<
* Ignoring the response-body
* Connection #0 to host localhost left intact
* Issue another request to this URL: 'http://localhost/web/test/sv2.php'
* Re-using existing connection! (#0) with host localhost
* Connected to localhost (127.0.0.1) port 80 (#0)
> GET /web/test/sv2.php HTTP/1.1
Host: localhost
Accept: */*
Cookie: data=1234; lightbox=winofsql
< HTTP/1.1 200 Document follows
< MIME-Version: 1.0
< Server: AnWeb/1.42p
< Date: Fri, 18 Jun 2010 02:35:32 GMT
< Transfer-Encoding: chunked
< Expires: -1
< Pragma: no-cache
< Cache-control: no-cache
< Last-Modified: Fri, 18 Jun 2010 02:35:32 GMT
< X-Powered-By: PHP/5.3.2
< Content-type: text/html
<
* Connection #0 to host localhost left intact
* Closing connection #0
関連する記事
VB.net : HttpWebRequest と HttpWebResponse でクッキーのやり取り