Microsoft Knowledge Base Article
This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved.
Terms
of Use |
Trademarks
Article ID: 290899 - Last Review: October 16, 2002 - Revision: 1.1
BUG: XMLHTTP Fails to Send Cookies from a Client
This article was previously published under Q290899
The
MSXML2.XMLHTTP object does not use cookies per se, but you can use it to send your own cookies from a client to a server. When you use the
MSXML2.XMLHTTP object to send your cookies from a client, you may find that your cookies are empty when they arrive at the server.
NOTE: Usually a server sends and receives cookies. In this case, you may be submitting cookies from a client so that you do not have to reauthenticate the client.
To work around this problem, invoke the
setRequestHeader method twice for the cookie.
Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
Steps to Reproduce Behavior
- Create the Windows script to send the cookie:
- Create a new text file by using Windows Notepad or another text editor.
- Paste the following code into the text file:
Dim http
set http = WScript.CreateObject("MSXML2.XMLHTTP")
http.open "GET", "http://localhost/user.asp", false
http.setRequestHeader "Cookie", "cookietest=testvalue"
'http.setRequestHeader "Cookie", "cookietest=testvalue"
http.send
WScript.Echo http.status
WScript.Echo http.responseText
- Save the text file as Cookie.vbs in a folder of your choice.
- Create the Active Server Pages (ASP) page to receive and return the cookie:
- Create a new text file by using Windows Notepad or another text editor.
- Paste the following code into the text file:
<%
Response.Write "Cookie: " & CStr(Request.ServerVariables("HTTP_COOKIE"))
%>
- Save the text file as User.asp in the C:\InetPub\WWWRoot folder or another physical path that corresponds to the home folder of your default Web site.
- At a command prompt, type the following to execute the Visual Basic Scripting Edition (VBS) script by using the Windows Scripting Host. Change the location of the file to refer to the folder where you saved the Cookie.vbs file:wscript c:\cookie.vbs
The cookie string that is returned is empty.
- In the file Cookie.vbs, uncomment the following line:
'http.setRequestHeader "Cookie", "cookietest=testvalue"
- Save Cookie.vbs.
- Again run Cookie.vbs by using the following:
Note that the cookie is returned successfully.
APPLIES TO
- Microsoft XML Parser 2.6
- Microsoft XML Parser 3.0
- Microsoft XML Parser 3.0 Service Pack 1
- Microsoft XML Core Services 4.0
| kbbug kbfix kbfix KB290899 |
Community Feedback System
Very often, it takes hours to solve a problem. Very often, you've looked high
and low, and have tried a lot of solutions. When you finally found it, chances
are, it was because someone else helped you. Here's your chance to give back.
Use our community feedback tool to let others know what worked for you and what
didn't.
Please also understand that the community feedback system is not warranted to be
correct, it's simply a system that we've built to let people try and help each
other. If something in a feedback response doesn't make sense to you, or you're
not comfortable making changes that the feedback talks about (like registry
edits), please consult a professional.
Thank you for using kbAlertz.com Feedback System.
-- Scott Cate