[英]file_get_contents return: sorry! something went wrong
I used the function file_get_contents to get content from a website. 我使用功能file_get_contents从网站获取内容。 but just see messege "sorry! something went wrong."
但只要看到messege“对不起!出问题了”。
My code here: 我的代码在这里:
<?php
$kkk = 'https://batdongsan.com.vn/phan-tich-nhan-dinh/thi-truong-can-ho-cao-cap-can-mot-su-sang-loc-khat-khe-ar97716';
$ddd = file_get_contents($kkk);
echo $ddd;
?>
Can you help me explain this error or any idea 你能帮我解释这个错误或任何想法吗
thank you so much! 非常感谢!
Yes, file_get_contents()
returns that msg "sorry! something went wrong." 是的,
file_get_contents()
返回msg,“抱歉!出了点问题。” for me also. 对我来说也是。 Make API call using PHP CURL .
使用PHP CURL进行 API调用。 Let's try like this way-
让我们尝试这样-
Note: 注意:
URL which is not retrieved by file_get_contents(), because their server checks whether the request come from browser or any script?.
无法通过file_get_contents()检索的URL,因为其服务器检查请求是来自浏览器还是任何脚本? If they found request from script they simply disable page contents.
如果他们发现了来自脚本的请求,他们只是禁用页面内容。
So that you have to make a request similar as browser request.
这样您就必须发出类似于浏览器请求的请求。 PHP Curl is suitable choice for this kind of job.
PHP Curl是此类工作的合适选择。 See here
看这里
<?php
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://batdongsan.com.vn/phan-tich-nhan-dinh/thi-truong-can-ho-cao-cap-can-mot-su-sang-loc-khat-khe-ar97716",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_POSTFIELDS => "",
));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.