简体   繁体   English

显示卷曲数据,空白页

[英]Displaying curl data, blank page

I'm trying to download json data using curl in PHP from companies house API. 我正在尝试从公司内部API使用PHP中的curl下载json数据。

Here is the example they provide that I'm trying to use: https://developer.companieshouse.gov.uk/api/docs/company/company_number/readCompanyProfile.html#here 这是他们提供的示例,供我尝试使用: https : //developer.companieshouse.gov.uk/api/docs/company/company_number/readCompanyProfile.html#here

The example: 这个例子:

curl -uYOUR_APIKEY_FOLLOWED_BY_A_COLON: https://api.companieshouse.gov.uk/company/{company_number}

My code 我的密码

<?php
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://api.companieshouse.gov.uk/company/01000000");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
    'curl -u8yUXrestOfmyApiKey:'
    ));
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($curl);
if(false == $result){
    echo curl_error($curl);
}
curl_close($curl);
print($result);

?>

Using header: 使用标题:

'-u my_api_key:8yUXGgcHznjaNWnKpuKIJ7yv7HDvU_slH273GuF1'

I get 400 - bad request and with header in my code above I get nothing no errors blank page no data. 我得到400-错误的请求,并且上面代码中的标头没有任何内容,没有错误,空白页没有数据。

PS. PS。 There is a company with number 01000000 I've checked 我已经检查了一家公司,编号为01000000

您应该添加CURLOPT_USERPWD

curl_setopt($curl, CURLOPT_USERPWD, "YOUR API KEY"); #Add your api key

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

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