Answer the question
In order to leave comments, you need to log in
How to solve the problem of cross-domain request?
Good afternoon. The site has a method that loads data from a third-party resource and when the request is executed it gives an error. How can this be resolved?
The 'Access-Control-Allow-Origin' header contains multiple values '*, *'
Answer the question
In order to leave comments, you need to log in
In some magical way, everything worked after the server was rebooted.
It is necessary that a third-party resource in its response give out the above header:
If there is no such header, then the security policy is included.
Here's a magic function for you. When you need a treasured page - use it.
For example:
$g = get_web_page("google.com");
echo $g['content'];
function get_web_page( $url ){
$uagent = $_SERVER["HTTP_USER_AGENT"];
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_ENCODING, "");
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 120);
curl_setopt($ch, CURLOPT_TIMEOUT, 120);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$page = curl_getinfo( $ch );
curl_close( $ch );
$page['errno'] = $err;
$page['errmsg'] = $errmsg;
$page['content'] = $content;
return $page;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question