是否有可能使用JavaScript来改变HTTP请求的头?有可能、JavaScript、HTTP

由网友(☆笑容→骗不过自己★)分享简介:pretty的多是什么标题问,是否有可能使用某种类型的JavaScript来改变/设置一个HTTP请求的头?Pretty much what the title asks, is it possible to use some kind of javascript to change / set a http re...

pretty的多是什么标题问,是否有可能使用某种类型的JavaScript来改变/设置一个HTTP请求的头?

Pretty much what the title asks, is it possible to use some kind of javascript to change / set a http request's header?

非常感谢您的关注:)

推荐答案

接头传递长JavaScript是下载前,更不用说跨preTED。简短的答案是否定的。

Headers are passed long before javascript is downloaded, let alone interpreted. The short is answer is no.

不过,如果你说在Ajax调用的上下文(让我们使用jQuery为例),请求头可写。

However, if you're speaking in the context of an ajax call (let's use jQuery as an example), the request headers can be written.

请参阅读取头从一个AJAX调用使用jQuery 。 请参见设置页眉使得AJAX调用使用jQuery

然而,如果你的JavaScript是服务器端(如Node.js的),这将是一个肯定的(可能不是因为岗位提到HTML):

However, if your javascript is server-side (e.g. node.js) that would be a yes (probably not since the post mentions HTML):

var body = 'hello world';
response.writeHead(200, {'Content-Length': body.length,'Content-Type': 'text/plain' });
阅读全文

相关推荐

最新文章