当我尝试从我的/dev/get-comments调用GET终结点时遇到错误。现在,我的应用程序接口工作了,因为我的另一个GET /dev/get-posts端点工作得很好,两者之间唯一的区别是第一个端点使用了一个请求体。
API.get("holler-api", "/get-comments", {
body: {postId: this.props.post.postId}
}).then(result => {
if(result.Count > 0) {
this.setState({
comments: result.Items
});
}
})
.catch(err => console.log(err));XHR GET https://xxxxxxxxxx.execute-api.us-east-1.amazonaws.com/dev/get-comments
[HTTP/2 403 Forbidden 23ms]这是解释错误的请求响应,没有太大帮助!
SyntaxError: JSON.parse: bad control character in string literal at line 1 column 191 of the JSON data
{"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.
The Canonical String for this request should have been
'GET
/dev/get-comments发布于 2020-08-16 07:52:17
简单地说,API网关不支持GET请求的请求体,所以需要使用path参数。

解决方案是将我的所有GET lambda函数转换为使用路径参数,并按如下方式调用API:
API.get("holler-api", `/get-comments/${this.props.post.postId}`)
.then(result => {
if(result.Count > 0) {
console.log(result.Items);
this.setState({
comments: result.Items
});
}
})
.catch(err => console.log(err));https://stackoverflow.com/questions/63431823
复制相似问题