尝试在PHP中使用--location参数发出cURL请求
我想用PHP实现以下请求:尝试在PHP中使用--location参数发出cURL请求,php,curl,php-curl,Php,Curl,Php Curl,我想用PHP实现以下请求: curl--location--request GET'xxx.xxxxx ad.com/api/rest/issues?project_id=4'-H'授权:xxxxxxxxxxxxxxxxxxxxxxxxxxx htb' 我实现的代码是: <?php $url = "xxx.xxxxxad.com/api/rest/issues?project_id=4"; $ch = curl_init(); curl_setopt($ch, CURLOPT
curl--location--request GET'xxx.xxxxx ad.com/api/rest/issues?project_id=4'-H'授权:xxxxxxxxxxxxxxxxxxxxxxxxxxx htb'
我实现的代码是:
<?php
$url = "xxx.xxxxxad.com/api/rest/issues?project_id=4";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, array('Authorization:xxxxxxxxxxxxxxxxxxxxxxxxxxxHTb'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$output = curl_exec($ch);
echo $output;
curl_close($ch);
?>
我找不到在请求中包含--location
的方法,如果没有该方法,则无法获取数据。--request GET
大致翻译为CURLOPT\u HTTPGET=>1
(实际上,严格的翻译是CURLOPT_CUSTOMREQUEST,但不要这样做,如果/当你将来尝试在其他东西上重复使用curl句柄而忘记重置它时,这通常是一个导致错误的坏主意-CUSTOMREQUEST很容易出现错误,根据经验法则:尽可能避免。)
另外,CURLOPT_HEADER
做了一些完全不同的事情(您可以在这里阅读:),您需要实际设置自定义头的是CURLOPT_HTTPHEADER
,简而言之:
curl_setopt_array($ch, array(
CURLOPT_HTTPGET => 1,
CURLOPT_HTTPHEADER => array(
'Authorization:xxxxxxxxxxxxxxxxxxxxxxxxxxxHTb'
),
CURLOPT_URL => 'xxx.xxxxxad.com/api/rest/issues?project_id=4'
));
您的问题不够清楚。请检查您使用的第一句话。请仔细阅读
--location
的功能,然后阅读PHP curl\u setopt的手册页面,并尝试找出等效的功能是什么…?您可能希望CURLOPT\u FOLLOWLOCATION
也可以更改您的访问密钥,因为这对具有ho真的很想,或者只是很无聊,想知道你在使用哪个域名,现在他们有了你的访问密钥。(编辑你的帖子是不够的,所以有一个编辑历史记录)