ovh 400 错误请求响应

问题描述

尝试在 laravel 代码中使用 ovh API 创建子域时出现此错误

POST https://eu.api.ovh.com/1.0/domain/zone/mondomain.com/record resulted in a 400 Bad Request response: {"message":"Invalid signature","httpCode":"400 Bad Request","errorCode":"INVALID_SIGNATURE"}

我的 PHP 代码如下:

$ovh = new Api(
    $applicationKey,// Application Key
    $applicationSecret,// Application Secret
    'ovh-eu',// Endpoint of API OVH Europe (List of available endpoints)
    $consumerKey
); // Consumer Key

$result = $ovh->post(
    '/domain/zone/mondomain.com/record',array(
        'fieldType' => 'A',// Resource record Name (type: zone.NamedResolutionFieldTypeEnum)
        'subDomain' => 'test-sousdomain',// Resource record subdomain (type: string)
        'target' => 'monIP',// Resource record target (type: string) ssh root@
        'ttl' => '0',// Resource record ttl (type: long)
    )
);
return $result;

感谢您的帮助。

解决方法

INVALID_SIGNATURE 表示缺少某些参数或某些值与请求的参数类型不匹配(stringlong 等)

在您的情况下,参数 ttl 需要是 long,但您给了它 string

应该更好:

$result = $ovh->post('/domain/zone/mondomain.com/record',array(
    'fieldType' => 'A',// Resource record Name (type: zone.NamedResolutionFieldTypeEnum)
    'subDomain' => 'test-sousdomain',// Resource record subdomain (type: string)
    'target' => 'monIP',// Resource record target (type: string) ssh root@
    'ttl' => 0,// Resource record ttl (type: long)
));

这里唯一的区别是 '0'0(没有简单的引号)

签名可以在这里找到:/domain/zone/{zone_name}/record

如果您通过此 API 控制台执行请求,则在 Raw 选项卡中您可以看到生成的请求:

{
  "fieldType": "A","subDomain": "test-sousdomain","target": "monIp","ttl": 0
}