javascript - AWS POST 到 API Gateway 返回 415“不支持的媒体类型”
问题描述
我目前正在尝试直接设置对我的 DynamoDB 表的 API Gateway 代理调用。我已设置好所有内容,以便 API Gateway 控制台中的测试返回预期结果:
{
"Items": [
{
"zoneID": "Northern",
"location": "Pro Skate Shop",
"address": "123 Fake Street",
"exposureDate": "04/06/2021",
"exposureWindow": "16:00 - 17:30",
"advice": "get tested immediately"
}
]
}
如果我curl
是我的端点,我也会得到预期的响应:
$ curl -X POST https://<API URL>/dev/getcontacts
{
"Items": [
{
"zoneID": "Northern",
"location": "Pro Skate Shop",
"address": "123 Fake Street",
"exposureDate": "04/06/2021",
"exposureWindow": "16:00 - 17:30",
"advice": "get tested immediately"
}
]
}
但是,当我从我的应用程序调用时:
export function GetContacts() {
const [contacts, setContacts] = useState([]);
const url = '/getcontacts'
useEffect(() => {
async function callApi() {
try {
const contactList = await API.post('testapi', url)
console.log("results: ", contactList)
setContacts(contactList.Items)
} catch (err) { console.log({err})}
}
if (contacts.length === 0) {
callApi()
}
}, [contacts, url])
我在控制台中收到以下错误:
Failed to load resource: the server responded with a status of 415 ()
我假设这只是与请求标头有关(它被发送为application/json
),但我真的不确定如何解决这个问题。
任何帮助将不胜感激!
解决方案
推荐阅读
- html - HTML 打印到 PDF - 为表格单元格中的长文本重复页眉和页脚
- c++ - 如何通过值 C++ 传递 char*?
- aframe - 如何使用 webxr API 从 webxr 获取现有的 webxr 会话视频帧?
- django - 如何在 pyrebase 的键值对中的值内创建一个孩子?
- vba - 如何在一个instr中传递多个值?
- reactjs - 如何传递来自不同组件(关于和联系)的道具?不是父母对孩子。使用反应打字稿
- javascript - 如何在登录后 AirBnb 屏幕可用时单击某个 Airbnb 按钮并以编程方式进行更改?
- java - Blaze Persistence Join 子查询问题
- dapr - Dapr 并使用 sql statestore 代替 redis
- excel - 自动填充找到的列中的值