HTTP 标头变为小写 [英] HTTP headers became lowercased

查看:50
本文介绍了HTTP 标头变为小写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 html 页面.按下提交按钮后,请求正在发送.我的问题是请求的标头被小写了!我使用 IE 是因为它是公司限制.

I have the html page. After submit button was pressed the request is being sent. My problem is that request's headers are downcased! I use IE because it is corporative limits.

<html>
<head>
<script language="JavaScript" type="text/javascript">

function AjaxRequest(url,callback,method){
        var req = new XMLHttpRequest();
        req.onreadystatechange= function(){
                if(req.readyState != 4) return;
                callback(req);
        }
        req.open(method,url,true);

        var hdrsArr =  document.getElementById('headers').value.split('&');
        for (var i = 0; i < hdrsArr.length; i++){
            var p = hdrsArr[i].split('=');
            req.setRequestHeader(p[0],p[1]);
        }

        var params =  document.getElementById('params').value ;
        req.send(params);
}
function AjaxResponse(res){}
function MakeRequst(){
        alert('');
        var url = "http://localhost:8080/test-servlet/TestServlet";
        AjaxRequest(url,AjaxResponse,"POST");
}
</script>
</head>
<body>
<input type='text' id="headers" size="200" value='key=value&SOAPAction=requestCreditBureau&Content-Type=text/xml;charset=UTF-8&Accept=text/xml'/><br>
<input type='text' id="params" size="200" value='<?xml version="1.0" encoding="UTF-8"?><CB_Document appl="00000000000127725161" >[....]</CB_Document>'/><br>
<input type='button' value='doPost' onClick="MakeRequst();"/><br>
<div id="response_div"></div>
</body>
</html>

推荐答案

根据 HTTP RFC 2616,标头字段名称不区分大小写.引用如下:

By HTTP RFC 2616, header field names are case-insensitive. Quote from it below:

HTTP 标头字段,包括通用标头(第 4.5 节),请求标头(第 5.3 节)、响应标头(第 6.2 节)和实体标题(第 7.1 节)字段,遵循相同的通用格式在 RFC 822 [9] 的第 3.1 节中给出.每个头域包括后跟冒号(:")和字段值的名称.字段名称不区分大小写.字段值前面可以有任意数量的LWS,但首选单个 SP.标题字段可以扩展通过在每个额外的行前面加上至少一个 SP 来跨越多行或 HT.应用程序应该遵循通用形式",其中一个是已知的或指示,在生成 HTTP 构造时,因为可能存在一些无法接受任何东西的实现

HTTP header fields, which include general-header (section 4.5), request-header (section 5.3), response-header (section 6.2), and entity-header (section 7.1) fields, follow the same generic format as that given in Section 3.1 of RFC 822 [9]. Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive. The field value MAY be preceded by any amount of LWS, though a single SP is preferred. Header fields can be extended over multiple lines by preceding each extra line with at least one SP or HT. Applications ought to follow "common form", where one is known or indicated, when generating HTTP constructs, since there might exist some implementations that fail to accept anything

这是标准行为,所有浏览器栏 IE6 都符合这一点.因此,如果这给您带来了问题,您将在更改 XMLHttpRequest 对象行为(它不是用户空间可修改的)时遇到严重问题.你用标题做什么?

This is standard behaviour, and all browsers bar IE6 conform to this. As such, if this poses a problem to you, you will have serious issues changing the XMLHttpRequest object behaviour (it is not userland-modifiable). What are you doing with the headers?

(今日幸运饼干:让您的应用严格控制发送的内容,宽大接收的内容 完美适用于此.期望接收小写、大写、camelcase 标头...但在您发送的所有内容上均符合 RFC)

(Fortune cookie of the day: make your app strict on what it sends, lenient on what it receives applies perfectly to this. Expect to receive a mix of lower-case, upper-case, camelcase headers... But conform to RFCs on everything you send)

这篇关于HTTP 标头变为小写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆