HTTP headers became lowercased

戏子无情 提交于 2019-12-13 06:17:45

问题


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>

回答1:


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

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

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?

(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)




回答2:


Is it important to you that your headers are not downcase?

If it is, it shouldn't according to RFC 2616, all field names are case-insensitive.



来源:https://stackoverflow.com/questions/16174741/http-headers-became-lowercased

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!