相关文章推荐
不要命的汉堡包  ·  WebView全面解析 ·  1 月前    · 
一直单身的柚子  ·  IllegalArgumentExcepti ...·  1 月前    · 
聪明伶俐的围巾  ·  C-APDU R-APDU - ...·  9 月前    · 
幸福的番茄  ·  mongodb C# exception ...·  1 年前    · 
犯傻的铅笔  ·  iOS :Object-C ...·  1 年前    · 

本文可帮助你在使用 XMLHttpRequest setRequestHeader 方法和 Cookie 时解决问题。

原始产品版本: Internet 信息服务
原始 KB 编号: 234486

使用 XML 文档对象模型 (DOM) 时, setRequestHeader 对象上 XMLHttpRequest 的方法似乎不会按预期设置 Cookie 标头。 第一次调用 setRequestHeader Cookie HTTP 标头似乎没有效果。

若要向请求添加 Cookie,必须重复对 Cookie 标头的调用 setRequestHeader ,因为忽略第一个调用:

'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"

以这种方式设置 Cookie 是异常的。 Cookie 最好由使用标头的 Set-Cookie 服务器设置。