Php Postcode.tech授权因某种原因不起作用
我已经做了几次尝试,现在让这个荷兰postcode.tech api通过一个CURLOPT开始工作,但似乎没有什么能让它工作 代码如下:Php Postcode.tech授权因某种原因不起作用,php,Php,我已经做了几次尝试,现在让这个荷兰postcode.tech api通过一个CURLOPT开始工作,但似乎没有什么能让它工作 代码如下: <?php $headers = array( 'Bearer: f87d5d41-2495-47bf-8646-7fa1c46512e8' ); echo $headers; //The URL that we want to GET. $url = 'https://postcode.tech/api/v1/postcode/full
<?php
$headers = array(
'Bearer: f87d5d41-2495-47bf-8646-7fa1c46512e8'
);
echo $headers;
//The URL that we want to GET.
$url = 'https://postcode.tech/api/v1/postcode/full?postcode=1111XX&number=123';
//Initialize cURL.
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
//Set the URL that you want to GET by using the CURLOPT_URL option.
curl_setopt($ch, CURLOPT_URL, 'https://postcode.tech/api/v1/postcode/full?postcode=1446WJ&number=88');
//Set CURLOPT_RETURNTRANSFER so that the content is returned as a variable.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//Set CURLOPT_FOLLOWLOCATION to true to follow redirects.
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
//Execute the request.
$data = curl_exec($ch);
//Close the cURL handle.
curl_close($ch);
//Print the data out onto the page.
echo $data;
?>
我在尝试时不断收到{“message”:“Unauthorized”},但头/键正确无误。授权头的有效语法:
授权:
因此,改变:
$headers=数组('Bearer:f87d5d41-2495-47bf-8646-7fa1c46512e8')代码>
致:
$headers=array(“授权:承载f87d5d41-2495-47bf-8646-7fa1c46512e8”)代码>
输出:
{"postcode":"1446WJ","number":88,"street":"Volume","city":"Purmerend","municipality":"Purmerend","province":"Noord-Holland","geo":{"lat":52.509485977219,"lon":5.0036936976488}}
授权头
的一些背景,您可以考虑不公开API密钥…使用Prxman或类似的工具来调试任何HTTP请求。使用授权令牌尝试请求后…:-)。。。我也犯了同样的未经授权的错误。似乎您的承载令牌无效或API有故障。标头语法确实错误,感谢您的回复,我已经修复了它。