我正在尝试这样做
$str = '{ "Json": ' . file_get_contents("http://studiofutbol.com.ec/?feed=json") . '}';
但我一直得到错误:未能打开流:HTTP请求失败!HTTP1.1 403 Forbidden,当我试图使用curl获取内容时,我得到了我已经被禁止的消息。HTTP1.1 403 Forbidden,当我试图使用curl获取内容时,我得到的信息是我已经被禁止。什么是奇怪的是,我可以做。
$str = '{ "Json": ' . file_get_contents("http://studiofutbol.com.ec/") . '}';
没有问题,我得到的所有内容。我不知道发生了什么事,与"http:/studiofutbol.com.ec?feed=json。"这个链接。
我还试过$str = '{ "Json": '. file_get_contents("http:/studiofutbol.com.ec?feed=json。") . '}'; 从另一个完全不同的服务器,它的工作,所以可能发生了什么?
另外,我是服务器管理员。我使用cloudflare,它是一个wordpress网站,你可能会看到。
PD:我刚刚安装了wprocket,我注意到了这一点,就在那之后。
EDIT:现在我使用$str = '{ "Json": ' . file_get_contents("http:/127.0.0.1?feed=json。") . '}';就能用了,但我还是不知道被禁的东西是怎么回事?
是的,一些主机提供商限制 file_get_contents()
函数。相反,你应该使用
wp_remote_get("http://studiofutbol.com.ec/")