简体   繁体   English

获取请求适用于邮递员但不适用于php的file_gets_content和cURL

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

Here is the url below, tried both with the method file_get_contents and curl...doesn't work from php script but works fine with postman. 这是下面的网址,尝试使用方法file_get_contents和curl ...不能从PHP脚本工作,但与邮递员工作正常。 Any idea why so??? 知道为什么这么说???

https://query.yahooapis.com/v1/public/yql?q= select * from weather.forecast where woeid in (SELECT woeid FROM geo.places WHERE text="(28.56,77.32)") and u='c'&format=json 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 request is as follows: 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);

Try with this one. 试试这个。 The difference is that the url is url encoded: 区别在于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