我想从api获取信息,代码如下:
<?php
$curl = curl_init();
$authorization = "Authorization: Token token='xxxxxx'";
$header = curl_setopt($curl, CURLOPT_HTTPHEADER, array($authorization));
curl_setopt($curl, CURLOPT_URL, "https://customr.heliumdev.com/api/v1/customers/xxxx");
$result = curl_exec($curl);
if(!curl_exec($curl)){
print_r('Error: "' . curl_error($curl) . '" - Code: ' .curl_errno($curl)."<br>");
}
curl_close($curl);
print_r(json_decode($result));
?>
我收到了Error: "Illegal characters found in URL" - Code: 3
原点卷曲应该是curl https://customr.heliumdev.com/api/v1/customers/xxxx --header "Authorization: Token token="xxx""
,关于非法字符的任何想法?
答案 0 :(得分:0)
我无法重现这个问题。
但是,我建议你避免不必要的双重执行curl_exec并使用$ result代替......
...
$result = curl_exec($curl);
if (!$result) {
...
}