0

在http请求头中,有一个名为“Upgrade”的字段,允许设置http协议升级。就像 WebSocket 握手的第一步是向服务器发送一个带有“升级”字段的 HTTP 请求。

我尝试了几种方法来设置 Http 请求标头中的“升级”字段:

1:

$.ajax({
    url: "/Http-Header-Test/ServerTest",
    type: "POST",
    beforeSend: function (xhr)
    {
        xhr.setRequestHeader("Upgrade", "Dummy Protocol");
    },
    success: function () {alert("Ajax call success")},
    error: function (error) { alert("Ajax call failed: "+ error.status + ": " + error.responseText)}
});

2:

$.ajax({
    url: "/Http-Header-Test/ServerTest",
    type: "POST",
    headers: {"Upgrade" : "Dummy Protocol" 
             },
    success: function () {alert("Ajax call success")},
    error: function (error) { alert("Ajax call failed: "+ error.status + ": " + error.responseText)}
});

3:

var client = new XMLHttpRequest();
client.open("POST", "/Http-Header-Test/ServerTest", false);
client.setRequestHeader("Accept", "TEST");
client.setRequestHeader("Upgrade", "Dummy Protocol");
client.send(null);

他们都不能修改 Http 请求标头中的“升级”字段。一件有趣的事情是可以设置“接受”字段。任何人都可以给我一些帮助吗?

4

0 回答 0