PHP中的卷曲通过获取请求

时间:2013-11-06 05:00:26

标签: php curl

我正在使用Curl。我想通过Curl访问网址。当我直接访问URL时,它工作正常。但通过卷曲它不会显示任何东西。 这是我的代码

$baseurl="https://www.addressfinder.co.nz/api/address?q=184+willis+st%2C+te+aro%2C+wellington+6011&key=9QTP8F3CHXEVU7WGYA6J&secret=KQLTAXY46M39RGHBFC8W&format=json";
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser
$res=curl_exec($ch);
echo $res; 

它什么都不显示。任何人都可以告诉我如何做到这一点。 感谢

2 个答案:

答案 0 :(得分:1)

它不使用SSL(http而非https

$baseurl="http://www.addressfinder.co.nz/api/address?q=184+willis+st%2C+te+aro%2C+wellington+6011&key=9QTP8F3CHXEVU7WGYA6J&secret=KQLTAXY46M39RGHBFC8W&format=json";
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_HEADER, false);

// grab URL and pass it to the browser
$res=curl_exec($ch);
echo $res; 

This fix似乎也有效:

$baseurl="https://www.addressfinder.co.nz/api/address?q=184+willis+st%2C+te+aro%2C+wellington+6011&key=9QTP8F3CHXEVU7WGYA6J&secret=KQLTAXY46M39RGHBFC8W&format=json";
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $baseurl);
curl_setopt($ch, CURLOPT_HEADER, false);

/* Turn off SSL verify peer */
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

// grab URL and pass it to the browser
$res=curl_exec($ch);
echo $res; 

答案 1 :(得分:0)

试试这个:

<?php
$baseurl="https://www.addressfinder.co.nz/api/address?q=184+willis+st%2C+te+aro%2C+wellington+6011&key=9QTP8F3CHXEVU7WGYA6J&secret=KQLTAXY46M39RGHBFC8W&format=json";
$locate = json_decode(file_get_contents($baseurl),true);

$address=$locate['completions']['0']['a'];
echo $address;
?>

这将为您提供所需的结果,您可以使用数组方法访问所有数据。