【发布时间】:2012-09-10 11:25:05
【问题描述】:
所以这似乎是一个常见的错误,但我已经尝试了所有方法,但它不起作用!
我的代码目前如下所示:
$apikey = "XXXXXXXXX";
$search_url = "https://www.googleapis.com/shopping/search/v1/public/products?key=$apikey&country=US&q=$item_title&restrictBy=gtin&alt=json";
$response = file_get_contents($search_url);
我已经尝试了从 urldecode 到 html_entity_decode/encode 到几乎所有我能找到的解决方案,但仍然得到相同的错误:
file_get_contents(https://www.googleapis.com/shopping/search/v1/public/products?key=XXXXX&country=US&q=THESTRING&restrictBy=gtin&alt=json) failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
如你所见,我得到的是 &s 而不是普通的 ol' & (&)
我记得有一个类似的问题,问题只是我在字符串的开头没有“http://”。但如您所见,这里并非如此。
谢谢!
【问题讨论】:
-
你能检查你的 php.ini 文件中是否启用了 allow_url_fopen 吗?或尝试其他网址,例如 $query=file_get_contents('youtube.com/watch?v=XiFrfeJ8dKM');
-
allow_url_fopen = On in php.ini 当我执行 file_get_contents("google.com") 时,我没有收到任何错误(并且打印 $response 按预期工作)。即使执行 file_get_contents("google.com/imghp?hl=en&tab=wi") 也有效
-
它们没有被更改为
&s,这只是为了在浏览器中正确格式化您的错误消息。