问题描述
我创建了一个api密钥并将其添加到我的函数中。然后,我已经部署了api并对其进行了测试,但仍然得到:
I have created an api key and added it to my functions. I have then deployed the api and tested it but still get:
"message": "Forbidden"
如何使用JSON请求传递api密钥,因为我一直在使用 x-api-key: theKey ?
How do I pass the api key with my JSON request as I have been using "x-api-key": "theKey"?
推荐答案
x-api-key
参数作为HTTP标头参数(即未添加到JSON正文)。如何传递HTTP标头取决于您使用的HTTP客户端。
The x-api-key
parameter is passed as a HTTP header parameter (i.e. it is not added to the JSON body). How you pass HTTP headers depend on the HTTP client you use.
例如,如果您使用curl并假设您 POST
JSON有效负载,则请求看起来像(将 [api-id]
替换为实际ID,将 [region]
替换为API的AWS区域) ):
For example, if you use curl and assuming that you POST
the JSON payload, a request would look something like (where you replace [api-id]
with the actual id and [region]
with the AWS region of your API):
$ curl -X POST -H "x-api-key: theKey" -H "Content-Type: application/json" -d '{"key":"val"}' https://[api-id].execute-api.[region].amazonaws.com
这篇关于在Amazon API Gateway中使用API密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!