所以這似乎是一個常見的錯誤,但我已經嘗試了一切,它只是不工作!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