所以这似乎是一个常见的错误,但我已经尝试了一切,它只是不工作!file_get_contents和&
我的代码目前看起来是这样的:
$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 /编码到几乎所有我能找到,但还是解决方案,得到了同样的错误:
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
,你可以看到,而不是纯醇” &(号),我得到&安培
我记得有一个simil这个问题很简单,就是我在字符串的开头没有“http://”。但正如你所看到的那样,情况并非如此。
谢谢!
你能粘贴phpinfo()吗? – GBD
你可以检查你的php.ini文件中是否启用了allow_url_fopen?或尝试另一个网址,如$ query = file_get_contents('http://www.youtube.com/watch?V = XiFrfeJ8dKM'); – GBD
allow_url_fopen =在php.ini中打开 当我做file_get_contents(“http://www.google.com”)时,我没有收到错误(并且打印$响应按预期工作)。 即使正在执行file_get_contents(“https://www.google.com/imghp?hl=en&tab=wi”)作品 – user1595077