简体   繁体   English

PHP Rest API获取

[英]PHP Rest API Get

I've tried a few different things, but everything I can find isnt working. 我尝试了几种不同的方法,但是我发现的所有方法都无法正常工作。 I have a photo URL, and am trying to access it with the appropriate authentication 我有一个照片网址,并正在尝试使用适当的身份验证进行访问

  $service_url = 'photo URL';
  $curl = curl_init($service_url);
  curl_setopt($curl, CURLOPT_HTTPHEADER, array('Bearer code'));
  curl_setopt($curl, CURLOPT_USERPWD, "Username:Password"); 
  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'GET'); // LINE 12

  curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true); 
  $curl_response = curl_exec($curl);
  $response = json_decode($curl_response);
  curl_close($curl);

  var_dump($response);

Obviously I'm trying to do a GET, but im not sure its working correctly. 显然,我正在尝试执行GET,但是我不确定它能否正常运行。 I'm also not sure that the 我也不确定

      curl_setopt($curl, CURLOPT_HTTPHEADER, array('Bearer code'));

line is working correctly. 线工作正常。

Any ideas? 有任何想法吗?

PS - The link is a https:// PS-链接是一个https://

Thanks! 谢谢!

I don't think this is a valid value for CURLOPT_HTTPHEADER 我认为这不是CURLOPT_HTTPHEADER的有效值

array('Bearer code')

You need a header name AND value, such as 您需要标头名称AND值,例如

array('Authorization: Bearer code')

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

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