0

私はhtmlページを持っています。送信ボタンが押された後、リクエストが送信されています。私の問題は、リクエストのヘッダーが小文字化されていることです! IEは法人限定なので使っています。

<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>
4

2 に答える 2

3

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)

于 2013-04-23T16:46:35.380 に答える
2

ヘッダーが小文字でないことは重要ですか?

そうである場合、 RFC 2616に従ってすべきではありません。すべてのフィールド名は大文字と小文字を区別しません。

于 2013-04-23T16:44:15.850 に答える