如何使用访问控制 - 允许 - 产地:https://www.example.com? [英] How to use Access-Control-Allow-Origin: https://www.example.com?

查看:140
本文介绍了如何使用访问控制 - 允许 - 产地:https://www.example.com?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打从HTTP网页HTTPS调用。我希望能解决这个问题,访问控制 - 允许 - 原产地。我如何使用它?

I want to make HTTPS calls from an HTTP webpage. I hope to solve this problem with Access-Control-Allow-Origin. How can I use it?

推荐答案

在HTTPS页面(你是从HTTP页面请求)设置页眉:

On the HTTPS page (that you are requesting from the HTTP page) set the header:

访问控制 - 允许 - 产地: http://www.example.com

Access-Control-Allow-Origin: http://www.example.com

您可以在PHP中做到这一点有:

You can do this in PHP with:

<?php
    header("Access-Control-Allow-Origin: http://www.requesting-page.com");
?>

另外,如果不工作,您可以在HTTP服务器(该请求是来自)上创建一个文件,该文件下载和显示的内容,这可以在PHP中加上:

Alternatively if that doesn't work, you could create a file on your HTTP server (where the request is coming from) that downloads and displays the contents, this can be done in PHP with:

<?php
    echo  file_get_contents("https://www.requested-page.com");
?>

我不会建议这样做,因为它需要更多的带宽,是不是好的做法,它应该只被使用,如果你不能做的第一选择。此外,如果开发商已经设置了访问控制,以限制它可能是有原因的。

I would not advise doing this as it requires extra bandwidth and isn't good practice, it should only be used if you can't do the first option. Furthermore, if a developer has set the access control to be restricted it's probably for a reason.

这篇关于如何使用访问控制 - 允许 - 产地:https://www.example.com?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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