0

我正在使用卷曲。我想通过 Curl 访问 url。当我直接访问 url 时,它工作正常。但通过 curl 它不显示任何内容。这是我的代码

$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; 

它什么也不显示。谁能告诉我如何做到这一点。谢谢

4

2 回答 2

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; 

此修复似乎也有效:

$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; 
于 2013-11-06T05:08:06.300 回答
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;
?>

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

于 2013-11-06T05:20:31.577 回答