繁体   English   中英

PHP PUT请求

[英]PHP PUT Request

我有一些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

我的问题是:

  1. 如何在通话中包含此内容?
  2. 以及如何根据上面的网址发送{domain_name}{period}

** 更新 **

发送标题如下:

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));

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM