大网数据广告活动
Web服务器与PHP

XMLHttpRequest setRequestHeader method and Cookies

· 52CE 我爱测

This article provides resolutions for the problem when you use XMLHttpRequest setRequestHeader method and Cookies.

This article helps you resolve the problem when you use XMLHttpRequest setRequestHeader method and Cookies.

Original product version:   Internet Information Services
Original KB number:   234486

Symptoms

When using the XML Document Object Model (DOM), the setRequestHeader method on the XMLHttpRequest object does not seem to set cookie headers as expected. The first call to setRequestHeader using the Cookie HTTP header seems to have no effect.

Resolution

To add cookies to the request, the call to setRequestHeader for the Cookie header must be repeated because the first call is ignored:

'this value is ignored, but the step is necessary
xmlRequest.setRequestHeader "Cookie", "any non-empty string here"
'set all cookies here
xmlRequest.setRequestHeader "Cookie", "cookie1=value1; cookie2=value2"

Note: Setting cookies in this manner is atypical. Cookies are best set by the server using the Set-Cookie header.

Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.

资料来源与适用范围

资料来源
Microsoft Learn / IT Pro troubleshooting
适用范围
See source applicability · Source date 09/24/2020
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY 4.0 (documentation), MIT (code samples)

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。