我可以改变浏览器发送的HTTP请求的头? [英] Can I change the headers of the HTTP request sent by the browser?

查看:659
本文介绍了我可以改变浏览器发送的HTTP请求的头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找到一个宁静的设计,想用HTTP方法( POST GET , ...)和HTTP头尽可能。我已经发现,HTTP方法 PUT 删除不是从浏览器的支持。

I'm looking into a restful design and would like to use the HTTP methods (POST, GET, ...) and HTTP headers as much as possible. I already found out that the HTTP methods PUT and DELETE are not supported from the browser.

现在我期待得到同样的资源不同的再presentations,并想通过改变请求接受头做到这一点。根据该接受头,服务器可以服务于同一个资源有不同的看法。

Now I'm looking to get different representations of the same resource and would like to do this by changing the Accept header of the request. Depending on this Accept header, the server can serve a different view on the same resource.

问题是,我没有找到一个方法来告诉我的浏览器来改变这个头。

Problem is that I didn't find a way to tell my browser to change this header.

<一个..> 标记有一个的 type属性,可以有一个MIME类型,看起来像一个很好的候选人,但头仍然是浏览器的默认(在Firefox它可以在约:配置与 network.http.accept.default 键)

The <a..> tag has a type attribute, that can have a mime type, looked like a good candidate but the header was still the browser default (in Firefox it can be changed in about:config with the network.http.accept.default key).

推荐答案

我不认为这是可能做到这一点在你试图做到这一点。

I don't think it's possible to do it in the way you are trying to do it.

接受的数据格式的指示是通过添加扩展到资源名称通常完成。所以,如果你有一个像资源

Indication of the accepted data format is usually done through adding the extension to the resource name. So, if you have resource like

/resources/resource

GET /资源/资源返回它的HTML重新presentation,以表明您希望它的XML重新presentation相反,你可以用下面的模式

and GET /resources/resource returns its HTML representation, to indicate that you want its XML representation instead, you can use following pattern:

/resources/resource.xml

您必须做在服务器端的接受内容类型确定的魔法,那么。

You have to do the accepted content type determination magic on the server side, then.

或者使用JavaScript作为詹姆斯建议。

Or use Javascript as James suggests.

这篇关于我可以改变浏览器发送的HTTP请求的头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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