首页 > 解决方案 > 请求标头值在 Chrome 中转换为大写

问题描述

我正在尝试从一个简单的网页向 SharePoint 服务器发布一个 http 帖子。此请求已在 Internet Explorer 上运行,但在 Chrome 上失败。

$.ajax({
    url:"http://redacted/_vti_bin/cellstorage.svc/CellStorageService",
    type:'POST',
    headers:{
     'MIME-Version': "1.0",
     'SOAPAction': "http://schemas.microsoft.com/sharepoint/soap/ICellStorages/ExecuteCellStorageRequest",
     'Content-Type': "multipart/related; type=\"application/xop+xml\"; boundary=\"urn:uuid:8cfcbb22-dd52-4889-b29d-9ff2dcf909b2\"; start=\"<f13ad06d-8530-4af1-8cf3-d6d75c1635d4@tempuri.org>\"; start-Info=\"text/xml; charset=utf-8\"",
     'X-Vermeer-Content-Type': "application/x-www-form-urlencoded"
    },

我的测试表明,除非请求标头大小写保持不变,否则我正在联系的 Web 服务 (/_vti_bin/cellstorage.svc/CellStorageService) 将失败:

内容类型:多部分/相关;类型=“应用程序/xop+xml”;边界="urn:uuid:8cfcbb22-dd52-4889-b29d-9ff2dcf909b2"; start="f13ad06d-8530-4af1-8cf3-d6d75c1635d4@tempuri.org"; 开始信息=“文本/xml;字符集=utf-8

但是,Chrome 似乎会自动将请求头值从“utf-8”转换为“UTF-8”,这可以通过 fiddler 输出来确认。这会导致错误:

POST http://redacted/_vti_bin/cellstorage.svc/CellStorageService 400(错误请求)

在此处输入图像描述

内容类型:多部分/相关;类型=“应用程序/xop+xml”;边界="urn:uuid:8cfcbb22-dd52-4889-b29d-9ff2dcf909b2"; start="f13ad06d-8530-4af1-8cf3-d6d75c1635d4@tempuri.org"; 开始信息=“文本/xml;字符集=UTF-8

由于我无法真正更改服务器服务,我想知道是否有办法强制 Chrome 使用小写标题值而不是转换它们。

类似帖子:

为什么 POST 请求的 Header Content-Type 在 chrome 和 firefox 之间仅在“UTF-8”和“utf-8”方面有所不同?

标签: javascriptajaxgoogle-chromesharepointhttp-post

解决方案


这导致了 chrome 上的亚马逊 aws 身份验证(GetFederationToken)问题,但不是 firefox 或 IE,因为它被用作签名的标头签名,我花了几个小时跟踪这个问题,希望这可以在遇到签名不匹配问题时拯救其他人

我认为 chrome 选择大写 UTF-8 没有任何理由:

https://www.w3.org/International/questions/qa-html-encoding-declarations


推荐阅读