是否有可能使用JavaScript来改变HTTP请求的头? [英] Is it possible to alter http request's header using javascript?

查看:127
本文介绍了是否有可能使用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 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' });

这篇关于是否有可能使用JavaScript来改变HTTP请求的头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆