Amazon web services 带颤振的Amazon-Lex授权
我想写一个与Amazon Lex REST API一起工作的颤振应用程序。Amazon有我使用的包制作所需标题的特定方法Amazon web services 带颤振的Amazon-Lex授权,amazon-web-services,flutter,amazon-lex,Amazon Web Services,Flutter,Amazon Lex,我想写一个与Amazon Lex REST API一起工作的颤振应用程序。Amazon有我使用的包制作所需标题的特定方法 Sigv4Client client = Sigv4Client( keyId: kAccessKey, accessKey: kSecretKey, region: "us-east-1", serviceName: "lex", ); final request = client.request( &quo
Sigv4Client client = Sigv4Client(
keyId: kAccessKey,
accessKey: kSecretKey,
region: "us-east-1",
serviceName: "lex",
);
final request = client.request(
"https://runtime.lex.us-east-1.amazonaws.com/bot/myBotName/alias/BETA/user/myUserId/text",
method: 'POST',
body: jsonEncode({'inputText': 'hi'}),
);
var response=post(request.url, headers: request.headers, body: request.body);
print(response.body);
但我得到的信息是:
{"message":"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details."}
我在邮递员身上得到了相同数据的有效回复。邮递员身上唯一不同的部分是“X-Amz-Content-Sha256”值,当然还有签名值(每次都会更改)。
“X-Amz-Content-Sha256”邮差值:
beaead3198f7da1e70d03ab969765e0821b24fc913697e929e726aeaebf0eba3
“X-Amz-Content-Sha256”我的代码值:
ee9ef87bd5a357cff93b1d83d1e8a1b47fb3fa2e94251711c6a30250119e6369
我试图编写函数来计算验证字符串,但它对我来说太复杂了。我更改了包并使用了 并按如下方式发送请求:
AwsSigV4Client client=AwsSigV4Client(
kAccessKey,
kSecretKey,
'https://runtime.lex.us-east-1.amazonaws.com',
region: 'us-east-1',
serviceName: 'lex',
);
final signedRequest = new SigV4Request(
client,
method: 'POST',
path: '/bot/MyBotName/alias/BETA/user/MyUser/text',
headers: new Map<String, String>.from({
'Content-Type': 'application/json; charset=utf-8',
'ACCEPT': 'application/json',
}),
body: new Map<String, dynamic>.from({"inputText": "hi"}),
);
var response = await http.post(
signedRequest.url,
headers: signedRequest.headers,
body: signedRequest.body,
);
在您的标题中。我也遇到了类似的问题。我设置了
defaultContentType:'application/json;在AWSSIGV4客户端中的charset=utf-8'
,并从SIGV4请求中删除了标题
:
AwsSigV4Client client=AwsSigV4Client(
accessKey,
secretKey,
'https://runtime.lex.eu-west-2.amazonaws.com',
region: 'eu-west-2',
serviceName: 'lex',
defaultContentType: 'application/json; charset=utf-8',
);
final signedRequest = new SigV4Request(
client,
method: 'POST',
path: '/bot/MyBotName/alias/BETA/user/MyUser/text',
body: new Map<String, dynamic>.from({"inputText": "hi"}),
);
AwsSigV4Client=AwsSigV4Client(
accessKey,
秘笈,
'https://runtime.lex.eu-west-2.amazonaws.com',
地区:“欧盟-西部-2”,
serviceName:'lex',
defaultContentType:'application/json;charset=utf-8',
);
final signedRequest=新SIGv4请求(
客户
方法:“POST”,
路径:'/bot/MyBotName/alias/BETA/user/MyUser/text',
body:newmap.from({“inputText”:“hi”}),
);
AwsSigV4Client client=AwsSigV4Client(
accessKey,
secretKey,
'https://runtime.lex.eu-west-2.amazonaws.com',
region: 'eu-west-2',
serviceName: 'lex',
defaultContentType: 'application/json; charset=utf-8',
);
final signedRequest = new SigV4Request(
client,
method: 'POST',
path: '/bot/MyBotName/alias/BETA/user/MyUser/text',
body: new Map<String, dynamic>.from({"inputText": "hi"}),
);