[英]cURL to PHP with header and username but without password
I've been trying and researching very hard but I haven't found an answer. 我一直在努力研究,但是没有找到答案。
I got following cURL: 我得到了cURL:
curl "https://someurl" -H "client-id: Fsomemorecharacters8=" -u "8somemorecharacters0:"
Testing in a command shell works perfectly. 在命令外壳中进行测试可以完美地进行。 But how can I get it to work with PHP?
但是如何使它与PHP一起使用? Usually its "username:password" but I got "username:" which is strange.
通常是它的“用户名:密码”,但是我却得到了“用户名:”,这很奇怪。
My PHP Code so far: 到目前为止,我的PHP代码:
<?php
$ch = curl_init();
$url = 'https://someurl';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, array('client-id: FHP20c+somemorecharacters8='));
curl_setopt($ch, CURLOPT_USERPWD, '85a15somemorecharacters4550:'); //Issue is here i think
$output = curl_exec($ch);
curl_close($ch);
?>
Do you have any idea how to make it work given -u "username:" instead of -u "username:password"? 您是否知道如何在给定-u“ username:”而不是-u“ username:password”的情况下使其工作?
Regards 问候
UPDATE
更新
See below for the answer! 答案见下文!
So I was able to solve it after all. 所以我毕竟能够解决它。
print curl_error($ch);
print curl_error($ch);
right after $output = curl_exec($ch);
$output = curl_exec($ch);
i found out that there is a "SSL certificate problem: self signed certificate in certificate chain". curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert-2017-09-20.pem");
curl_setopt ($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert-2017-09-20.pem");
Or you could use curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
which is, however, not recommended. $status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
I found out that my headers were missing. CURLOPT_HTTPHEADER
instead of CURLOPT_HEADER
. CURLOPT_HTTPHEADER
而不是CURLOPT_HEADER
。 So here is my full code: 所以这是我的完整代码:
<?php
$ch = curl_init();
$url = 'https://someurl';
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CAINFO, dirname(__FILE__)."/cacert-2017-09-20.pem");
//curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('client-id: client-id: FHP20c+somemorecharacters8='));
curl_setopt($ch, CURLOPT_USERPWD, '885a15somemorecharacters4550:');
$output = curl_exec($ch);
print curl_error($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
file_put_contents('output.txt', $output);
echo '<br><b>Output</b><br>' . $output;
echo '<br><b>Status-Code</b><br>' . $status_code;
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.