簡體   English   中英

獲取請求適用於郵遞員但不適用於php的file_gets_content和cURL

[英]get request works on postman but not with file_gets_content and cURL from php

這是下面的網址,嘗試使用方法file_get_contents和curl ...不能從PHP腳本工作,但與郵遞員工作正常。 知道為什么這么說???

https://query.yahooapis.com/v1/public/yql?q= select from from weather.forecast where woeid in(SELECT woeid FROM geo.places WHERE text =“(28.56,77.32)”)和u ='c “&格式= JSON

cURL請求如下:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 

$output = curl_exec($ch);   

// convert response
$output = json_decode($output);

// handle error; error output
if(curl_getinfo($ch, CURLINFO_HTTP_CODE) !== 200) {

  var_dump($output);
}
echo curl_error($ch);

curl_close($ch);

試試這個。 區別在於url是url編碼的:

$url = 'https://query.yahooapis.com/v1/public/yql?q=%20select%20*%20from%20weather.forecast%20where%20woeid%20in%20(SELECT%20woeid%20FROM%20geo.places%20WHERE%20text=%22(28.56,77.32)%22)%20and%20u=%27c%27&format=json';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 1);

$output = curl_exec($ch);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM