无法使用digeest curl从url检索数据
我不熟悉curl和API。我正在尝试使用API检索样本患者的信息 用户名和密码由数据库管理员提供。我试图使用摘要身份验证,但出现错误400。我正在跳过SSL证书验证。信息在我从邮递员那里提取的标题中 请参阅下面的代码无法使用digeest curl从url检索数据,curl,digest-authentication,Curl,Digest Authentication,我不熟悉curl和API。我正在尝试使用API检索样本患者的信息 用户名和密码由数据库管理员提供。我试图使用摘要身份验证,但出现错误400。我正在跳过SSL证书验证。信息在我从邮递员那里提取的标题中 请参阅下面的代码 <?php function patient() { $patient_id = '100'; // username & password $username = "abc"; $password = "1234"; $secretKey = "abc:1234"
<?php
function patient()
{
$patient_id = '100';
// username & password
$username = "abc";
$password = "1234";
$secretKey = "abc:1234";
$url = "https://example.com/patient/demographic?patient_id=".$patient_id;
// test dummy data
$post_data = array(
'name' => 'John',
'district' => 'Hawaii'
);
$header = array(
"Authorization: Digest username=\"abc\",
realm=\"mydomain.com\",
nonce=\"ad7a9ds798ds798d79asd79asd79asd\",
uri=\"/patient/demographic?patient_id=100\",
algorithm=\"MD5\",
response=\"kl345j3nk45lk34n5l34k5nl3k45nl345\",
opaque=\"gb56u7b56u7b56u7b567b567b5b765b\"",
"Cache-Control: no-cache"
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_ENCODING, "");
curl_setopt($curl, CURLOPT_MAXREDIRS, 10);
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($curl, CURLOPT_USERPWD, "$username:$password");
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_DIGEST);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post_data));
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err):
echo "Error: " . $err;
else:
// Show me the result
$transaction = json_decode($response, TRUE);
// curl_close($curl);
echo "Var dump";
echo "<br />";
var_dump($transaction['response']);
echo "<br />";
echo $transaction;
echo "<br />";
echo $response;
endif;
}
}
?>
错误是400个错误请求。请帮帮我。谢谢。考虑发布您收到的完整错误。错误400错误请求