php - 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
意味着某些参数丢失或某些值与请求的参数类型不匹配(string
等long
)
在您的情况下,参数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
}
推荐阅读
- acumatica - Acumatica 自定义任务和活动弹出窗口
- python - 如何为 Matplotlib 中的每个类别绘制具有不同类别的分类条形图?
- ios - 'OsmAndCore/QtExtensions.h' 文件未找到
- visual-studio - 查找并替换所有出现的函数定义
- dataframe - 如何绘制各县男女的折线图?
- amazon-web-services - 是否可以在 AWS 中触发 lambda init?
- r - RStudio 自动加载包
- swiftui - 如果我按下后退按钮,我如何在 UserDefaults SwiftUI 中为注销按钮重置数据?
- angular - this.contacts.push(contact) 有问题;& 如果(数据.n==1)
- linux - 使用 ad-hoc ansible 命令读取环境变量