这是我的基本身份验证卷曲代码:
<?php
///CURL
$data['item'] = 'example';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://100.100.100.100/items");
$headr = array();
$headr[] = 'Content-length: 0';
$headr[] = 'Content-type: application/json';
$headr[] = 'SourceSystem: system';
$headr[] = 'InteractionTime: 2017-07-13 11:06:00';
curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, "fakeusername:fakepassword");
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$output = curl_exec($ch);
if ($output === false)
{
print_r('Curl error: ' . curl_error($ch));
}
$info = curl_getinfo($ch);
var_dump($output);
var_dump($info);
?>
使用此代码,我总是返回代码401(身份验证失败)。在我与服务器的所有者讨论示例标题之前,这段代码中有什么问题吗?或者我可以在https服务器中考虑一些事情吗?
这是发布标题的示例:
POST / items HTTP / 1.1授权:基本FAKEBASE64PASSUSER =主机:100.100.100.100内容长度:0接受:application / json SourceSystem:system InteractionTime:2017-07-13 11:06:00 Expect:100-continue Content -type:application / json;边界= ---------------------------- 0665dac4f062