안녕하세요.
도메인에서
도메인의 api를 호출하여
제이쿼리로 데이터를 읽어오지 못하나요?
하루종일 주물러도 해결이 안되네요.ㅠㅠ
참고로 프로토콜이 동일할 경우에는 문제가 없습니다.
|
답변 6개 / 댓글 7개
채택된 답변
+20 포인트
Copy
function cUrlGetData($url, $post_fields = null, $headers = null) {
$ch = curl_init();
$timeout = 5;
curl_setopt($ch, CURLOPT_URL, $url);
if ($post_fields && !empty($post_fields)) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields);
}
if ($headers && !empty($headers)) {
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
$data = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
return $data;
}
$post_fields = null;
$headers = [
'accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9',
'sec-ch-ua: "Google Chrome";v="87", " Not;A Brand";v="99", "Chromium";v="87"',
'sec-ch-ua-mobile: ?0',
'user-agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36',
];
$res = cUrlGetData("http://www.bbb.com",$post_fields,$headers);
$res = json_decode($res, true);
print_r($res);
답변에 대한 댓글 6개
답변에 대한 댓글 1개
네...
https://aaa.com에서 http://bbb.com을 호출하면 데이터는 보이는데 가져오지를 못합니다.
개발자 모드에서 해당 URL을 클릭해 보면 결과값은 정상인데 "응답 데이터를 로드하지 못했습니다."라고 메시지가 보이네요.
https://aaa.com에서 http://bbb.com을 호출하면 데이터는 보이는데 가져오지를 못합니다.
개발자 모드에서 해당 URL을 클릭해 보면 결과값은 정상인데 "응답 데이터를 로드하지 못했습니다."라고 메시지가 보이네요.
답변을 작성하려면 로그인이 필요합니다.
서버사이드에서 우회하셔야합니다.