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?
Asked
Active
Viewed 3.6k times
10

bluish
- 26,356
- 27
- 122
- 180

user1874941
- 3,013
- 4
- 20
- 31
-
Search before asking... http://stackoverflow.com/a/6120260/1626399 – bobthyasian Dec 13 '12 at 10:25
-
I have already tried it and didn't work. – user1874941 Dec 13 '12 at 10:29
-
2The HTTPS server needs to send it's [access control _Allow-Origin_ and _Credentials_](https://developer.mozilla.org/en/docs/HTTP_access_control) headers which permit the origin of the ajax call. – Paul S. Dec 13 '12 at 10:56
2 Answers
10
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:
<?php
header("Access-Control-Allow-Origin: http://www.requesting-page.com");
?>
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.

Rob Farr
- 853
- 1
- 9
- 17
1
You can't, really. It's the browser preventing it. Security reasons. You can look into cURL. Read this posting: https-request-via-ajax-from-http-page

Community
- 1
- 1

bobthyasian
- 933
- 5
- 17