我有一些API系统的文档,它告诉我将PUT请求发送到服务URL,他们提供了这个:
PUT /domain/manage/renew/{domain_name}/{period}
以及发送请求的主URL。
我想这样做我需要使用cURL
所以我创建了以下内容:
$data = array("a" => $a);
$ch = curl_init($this->_serviceUrl . $id);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($data));
$response = curl_exec($ch);
if(!$response) {
return false;
}
但他们也说过:
The HTTP request header must contain the User, Hash and Encryption.
User: <username>
Hash: <authentication_hash>
Encryption: SHA-512
我的问题是:
{domain_name}
和{period}
?答案 0 :(得分:0)
**更新**
像这样发送标题:
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'User: '.$user, // change the variables to whatever you need, i.e. $this->user or whatever
'Hash: '.$hash, // same here
'Encryption: SHA-512'
]);
$response = curl_exec($ch);
if(!$response) {
return false;
}
对于URL,请执行以下操作:
$ch = curl_init('http://www.example.com/domain/manage/renew/'.urlencode($domain_name).'/'.urlencode($period));