简体   繁体   English

通过获取请求在PHP中卷曲

[英]Curl in PHP Via Get Request

I am using Curl . 我正在使用Curl。 i want to access url via Curl. 我想通过Curl访问URL。 When i direct Access url, it is working fine. 当我直接访问URL时,它工作正常。 but via curl it doesnot display anything. 但是通过curl它不会显示任何内容。 here is my code 这是我的代码

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

it doesn't display nothing. 它什么也不显示。 Can anybody tell me how to do this. 谁能告诉我该怎么做。 Thanks 谢谢

It works without SSL ( http not https ) 它在没有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 also appears to work: 此修复程序似乎也可以工作:

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

try this: 尝试这个:

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

This will give you the result you want and you can access all data using array methods. 这将为您提供所需的结果,并且您可以使用数组方法访问所有数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM