BUG: XMLHTTP fails to send cookies from a client

Source: Internet
Author: User
Tags send cookies
Dim logxml, idpw, postxml, info, cookie
Idpw = "id = ABC & PW = pass"
Set logxml = server. Createobject ("Microsoft. XMLHTTP ")
Logxml. Open "Post", "http: // myserver/login", false
Logxml. Send idpw
Cookie = logxml. getResponseHeader ("Set-cookie ")

Info = "Title = Hello & content = World"
Set postxml = server. Createobject ("Microsoft. XMLHTTP ")
Postxml. Open "Post", "http: // myserver/Post", false
Postxml. setRequestHeader ("cookie", cookie)
Postxml. setRequestHeader ("cookie", cookie)
Postxml. Send

Http://support.microsoft.com/default.aspx? SCID = KB; en-US; q290899
BUG: XMLHTTP fails to send cookies from a client symptoms

TheMsxml2.xmlhttpObject does not use cookies per se, but you can use it to send your own cookies from a client to a server. When you useMsxml2.xmlhttpObject 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 ES cookies. In this case, you may be submitting cookies from a client so that you do not have to reauthenticate the client. Resolution

To work around this problem, invokeSetRequestHeaderMethod twice for the cookie. Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.
More information

Steps to reproduce Behavior


1. Create the Windows Script to send the cookie:

A. Create a new text file by using Windows notepad or another text editor.
B. paste the following code into the text file:

 dim httpset HTTP = wscript. createobject ("msxml2.xmlhttp") HTTP. open "get", "http: // localhost/user. ASP ", falsehttp. setRequestHeader "cookie", "cookietest = testvalue" 'HTTP. setRequestHeader "cookie", "cookietest = testvalue" HTTP. sendwscript. echo HTTP. statuswscript. echo HTTP. responsetext 

C. Save the text file as Cookie. vbs in a folder of your choice.
2. Create the Active Server Pages (ASP) page to receive and return the cookie:

A. Create a new text file by using Windows notepad or another text editor.
B. paste the following code into the text file:

 <% response. write "Cookie:" & CSTR (request. servervariables ("http_cookie") %> 

C. 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.
3. 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.

4. In the file cookie. vbs, uncomment the following line:

'Http. setRequestHeader "cookie", "cookietest = testvalue"

5. Save cookie. vbs.
6. again run cookie. vbs by using the following:

 wscript c: \ cookie. vbs 

note that the cookie is returned successfully.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.