我一直在阅读有关 Access-Control-Allow-Origin 的内容,因为它似乎可以有效地允许跨域请求,因为我可以访问外部站点.我的问题是如何使用 Access-Control-Allow-Origin 来允许跨域请求.我试过这个(别笑)(顺便说一句,我想要一个数字,返回 1 或 0)
I've been reading about Access-Control-Allow-Origin because it seems effective at allowing cross domain requests since I have access to the external site. My question ism how do I use Access-Control-Allow-Origin to allow cross domain requests. I tried this (don't laugh) (by the way all I want is for a single number, 1 or 0 to be returned)
<html>
<head>
Access-Control-Allow-Origin: *
</head>
<body>
1
</body>
</html>
我接近了吗?谢谢你的帮助.如果有更简单的方法来执行简单的跨域请求,请告诉我.
Am I close? Thanks for your help. If there is an easier way to do a simple cross-domain request let me know.
这是一个HTTP头.您将配置您的网络服务器或网络应用程序以理想地发送此标头.也许在 htaccess 或 PHP 中.
That is an HTTP header. You would configure your webserver or webapp to send this header ideally. Perhaps in htaccess or PHP.
或者你也可以使用
Alternatively you might be able to use
<head>...<meta http-equiv="Access-Control-Allow-Origin" content="*">...</head>
我不知道这是否可行.并非所有 HTTP 标头都可以直接在 HTML 中配置.
I do not know if that would work. Not all HTTP headers can be configured directly in the HTML.
这可以替代许多 HTTP 标头,但请参阅下面的 @EricLaw 的评论.这个特定的标头是不同的.
This works as an alternative to many HTTP headers, but see @EricLaw's comment below. This particular header is different.
警告
这个答案是关于如何设置标题的.我对允许跨域请求一无所知.
This answer is strictly about how to set headers. I do not know anything about allowing cross domain requests.
关于 HTTP 标头
每个请求和响应都有标头.浏览器将其发送到网络服务器
Every request and response has headers. The browser sends this to the webserver
GET /index.htm HTTP/1.1
然后是标题
Host: www.example.com
User-Agent: (Browser/OS name and version information)
.. Additional headers indicating supported compression types and content types and other info
然后服务器发送响应
Content-type: text/html
Content-length: (number of bytes in file (optional))
Date: (server clock)
Server: (Webserver name and version information)
可以配置其他头文件,例如 Cache-Control,这完全取决于您的语言(PHP、CGI、Java、htaccess)和网络服务器(Apache 等).
Additional headers can be configured for example Cache-Control, it all depends on your language (PHP, CGI, Java, htaccess) and webserver (Apache, etc).
这篇关于如何使用访问控制允许来源?它只是在html头标签之间吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Angular 2:在本地 .json 文件中找不到文件Angular 2: file not found on local .json file(Angular 2:在本地 .json 文件中找不到文件)
使用模式 Angular 2 进行输入验证Input validation with pattern Angular 2(使用模式 Angular 2 进行输入验证)
如何在角度2中动态更改css类名How to change the css class name dynamically in angular 2(如何在角度2中动态更改css类名)
如何删除输入类型中的默认颜色?How to remove default color in input type?(如何删除输入类型中的默认颜色?)
如何将点击事件添加到打字稿中动态添加的html元How to add click event to dynamically added html element in typescript(如何将点击事件添加到打字稿中动态添加的html元素)
XPath 具有条件的多个属性值之一XPath one of multiple attribute values with condition(XPath 具有条件的多个属性值之一)