0

I want to get info from an api and the code is like:

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

and I got the error like Error: "Illegal characters found in URL" - Code: 3

the origin curl should be curl https://customr.heliumdev.com/api/v1/customers/xxxx --header "Authorization: Token token="xxx"", any idear about the illegal characters?

Gang Fan
  • 15
  • 5
  • In `xxxx` there are no illegal characters, but in the real string you provide to api - they __can__ be – u_mulder Jul 25 '17 at 15:19
  • Possible duplicate of [Which characters make a URL invalid?](https://stackoverflow.com/questions/1547899/which-characters-make-a-url-invalid) – Dale Wilson Jul 25 '17 at 15:19
  • @u_mulder Hi, I just tried `xxxx`, it still had errors – Gang Fan Jul 25 '17 at 15:26
  • @DaleWilson Hi, it seems my url only have `ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~:/?#[]@!$&'()*+,;=`.`, i cant find which part goes wrong – Gang Fan Jul 25 '17 at 15:29

1 Answers1

0

I could not reproduce the problem.

However, I suggest you avoid the unnecessary double-execution of curl_exec and use the $result instead...

...
$result = curl_exec($curl);
if (!$result) {
   ...
}