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

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

问题描述

我正在研究一种宁静的设计,并希望尽可能多地使用 HTTP 方法(POSTGET、...)和 HTTP 标头.我已经发现浏览器不支持 HTTP 方法 PUTDELETE.

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.

现在我希望获得相同资源的不同表示,并希望通过更改请求的 Accept 标头来实现此目的.根据这个 Accept 标头,服务器可以为同一资源提供不同的视图.

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.

<a..> 标签有一个 type 属性,可以有一个 mime 类型,看起来是一个不错的候选,但标题仍然是浏览器的默认值(在 Firefox 中,它可以在 about:confignetwork.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/resources/resource 返回其 HTML 表示,以指示您想要其 XML 表示,您可以使用以下模式:

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.

或者按照 James 的建议使用 Javascript.

Or use Javascript as James suggests.

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

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