首页 > 解决方案 > 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;

感谢您的帮助。

标签: phpapirecordovh

解决方案


INVALID_SIGNATURE意味着某些参数丢失或某些值与请求的参数类型不匹配(stringlong

在您的情况下,参数ttl需要是 a long,但您给了它 a 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'vs 0(没有简单的引号)

可以在此处找到签名:/domain/zone/{zone_name}/record

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

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

推荐阅读