我正在尝试使用 php 和 curl 查询多个域名的可用性,但我似乎无法得到有效的响应。
API: https ://api.godaddy.com/v1/domains/available
此处的文档: https ://developer.godaddy.com/doc/endpoint/domains#/v1/availableBulk
我的代码如下。任何帮助将非常感激。
$domains = array("name.com", "test.com", "monkey123er.com", "Sally123.co");
$domainsJSON = json_encode($domains);
// see GoDaddy API documentation - https://developer.godaddy.com/doc
// url to check domain availability
$url = "https://api.godaddy.com/v1/domains/available".
// see GoDaddy API documentation - https://developer.godaddy.com/doc
// set your key and secret
$header = array(
'Authorization: sso-key XXX:XXXX'
);
//open connection
$ch = curl_init();
$timeout=60;
//set the url and other options for curl
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,false);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'POST'); // Values: GET, POST, PUT, DELETE, PATCH, UPDATE
curl_setopt($ch, CURLOPT_POSTFIELDS, $domainsJSON);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
//execute post and return response data.
$result = curl_exec($ch);
//close curl connection
curl_close($ch);
// decode the json response
$dn = json_decode($result, true);
echo '<pre>'; print_r($dn); echo '</pre>';