How to use Access-Control-Allow-Origin: https://www.example.com?

前端 未结 2 1255
渐次进展
渐次进展 2021-02-14 10:13

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?

2条回答
  •  心在旅途
    2021-02-14 10:42

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

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

    You can do this in PHP with:

    
    

    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:

    
    

    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.

提交回复
热议问题