問題描述
是否可以在發(fā)送 http 消息之前使用 javascript/XmlHttpRequest 刪除一些特定的 http 標頭?
Is it possible to, before sending a http message, remove some specific http headers using javascript / XmlHttpRequest ?
我使用的是專有瀏覽器,因此無法使用特定于瀏覽器的解決方案.
I'm using a proprietary browser, so there's no way to do it using browser specific solution.
例如,我想在發(fā)送消息之前刪除標題授權(quán)"
For example, I want to remove the header 'Authorization' before send the message
POST /social/rpc?oauth_version=1.0& ... HTTP/1.1
Accept: text/html, image/png, image/*, */*
Accept-Language: ko
Authorization: Basic Og==
Host: test.myhost.com
問候
推薦答案
假設(shè)您的瀏覽器支持,您可以使用 XmlHttpRequest 對象的 setRequestHeader 方法,它是 W3C 規(guī)范.IE也實現(xiàn)了.
You could use the setRequestHeader method of the XmlHttpRequest object assuming your browser supports it, It is part of the W3C spec. It is also implemented by IE.
var req = new XMLHttpRequest();
req.setRequestHeader("Authorization", "");
這篇關(guān)于如何在 Javascript 中刪除 HTTP 特定的標頭的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!