[英]PHP Rest Api multiple paramaters how to send with curl
Getting stuck at post to a Rest API with multiple arguments.卡在 Rest API 与多个 arguments 的岗位上。 I'm trying to change nameservers with an API.我正在尝试使用 API 更改名称服务器。
The error i get: "ObjectInvalid|Nameserver object invalid. Minimum of 2 nameservers is required.".
我得到的错误: "ObjectInvalid|Nameserver object invalid. Minimum of 2 nameservers is required.".
I understand the "ns" part is wrong.我理解“ns”部分是错误的。 In the guide i only find this: "ns": [{ns="ns1.domain.com", nsip=""},{ns="ns2.domain.com", nsip=""}],
在指南中我只找到这个: "ns": [{ns="ns1.domain.com", nsip=""},{ns="ns2.domain.com", nsip=""}],
This is my code:这是我的代码:
$values = array(
"domain" => "mydomain.com",
"ns" => "[{ns='ns1.domain.com', nsip=''},{ns='ns2.domain.com', nsip=''}]",
"contact_id" => 123456,
"years" => 1
);
// Set POST to 1 and send the array with values as a JSON-string
curl_setopt_array($curl, array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_TIMEOUT => 30,
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => json_encode($values),
CURLOPT_URL => "https://www.apiurl.com/api/v1/domains/$domain/update",
CURLOPT_HTTPAUTH => CURLAUTH_ANY,
CURLOPT_USERPWD => "username:password"
));
It's hard to tell exactly without seeing the documentation, but most probably you should leave the serialization of the nameservers to json_encode
too:如果没有查看文档,很难准确判断,但很可能您也应该将名称服务器的序列化留给json_encode
:
$values = array(
"domain" => "mydomain.com",
"ns" => [
[
"ns" => "ns1.domain.com",
"nsip" => ""
],
[
"ns" => "ns2.domain.com",
"nsip" => ""
],
],
"contact_id" => 123456,
"years" => 1
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.