且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

file_get_contents 无法打开流:HTTP 请求失败!HTTP/1.1 500 内部 >服务器错误

更新时间:2021-10-17 08:35:11

file_get_contents(阅读蓝色矩形的提示)可以通过 php.ini 避免使用它.当您想从其他站点获取数据时,请改用 curl.http://php.net/manual/en/book.curl.php,有很多选项可以与 curl 一起使用,通过播放一些以下代码可以与您的 url 一起使用.

file_get_contents (read the tip on blue rectangle) can be easily blocked on server side through php.ini avoid using it. When you want to get data from an other site use curl instead. http://php.net/manual/en/book.curl.php, there are plenty of options that you can use with curl, by playing a bit the following code can work with your url.

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch,CURLOPT_URL,"https://cgi.ebay.com/ws/eBayISAPI.dll?ViewItemRevisionDetails&item=272908801183");
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
$data = curl_exec($ch);
curl_close($ch);

通过回显 $data 变量,您可以看到整个页面.

and by echoing the $data varible you can see the whole page.

echo $data;

您可以尝试使用 php DOM 方法解析页面中的数据并将它们转换为您想要的数据类型(对象类、数组等).

you can try parsing the data from the page by utilizing php DOM Methods and convert them to the data type you want (object class, array etc).