繁体   English   中英

PHP API发送POST请求

[英]PHP API sending POST requests

我有连接到外部API的此函数:

function ICUK_Request($url, $method = 'GET', $body = NULL) {
        $client = new IcukApiClient();
        $client->username = "user";
        $client->key = "pass";
        $client->encryption = "SHA-512";

        $req = new IcukApiRequest();
        $req->url = $url;
        $req->method = $method;

        if(!is_null($body)) {
            $req->body = $body;
        }

        $res = $client->send($req);
        if ($res->success) {
            $obj = json_decode($res->response);
        }
        else {
            throw new Exception('There was an error contacting the API.');
        }

        return $obj;
    }

API文档告诉我发送POST请求,如下所示:

POST /domain/registration/new/
{
   "domain_name": "domain.co.uk",
   "hosting_type": "NONE",
   "registration_length": 1,
   "auto_renew": false,
   "domain_lock": false,
   "whois_privacy": false,
   "contact_registrant_id": 1
}

所以我尝试了这个:

$arr = array(
    "domain_name" => "domain.co.uk",
   "hosting_type" => "NONE",
   "registration_length" => 1,
   "auto_renew" => false,
   "domain_lock" => false,
   "whois_privacy" => false,
   "contact_registrant_id" => 1
);

ICUK_Request("/domain/registration/new", "POST", $arr);

但这就是在API日志中给我的答复:

{
  "exception_message": "Internal API exception occured",
  "exception_type": "InternalApiException"
}

我不确定这是否是通用的,是否有人可以提供有关如何过帐数据的帮助?

将其作为json发送:

$values = json_encode($arr);
ICUK_Request("/domain/registration/new", "POST", $values);

暂无
暂无

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

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