我有一个端点可以将项目添加到“MasterList”dynamoDB 表
@app.route('/save_listing', methods=['POST'], content_types=['application/json'], cors=cors_config)
def post_item():
try:
data = app.current_request.json_body
except Exception as e:
data = e
try:
insert_item({
'pk': data['sku'],
"account" : data['account']
})
except Exception as e:
return str(e)
return str(data)
当我使用邮递员 POST 时,它会添加到表中,并返回数据字符串。
现在我正在尝试在 ReactJS 中实现相同的 POST
createListing(listing) {
console.log(listing)
fetch('https://z3sr9ja4zf.execute-api.us-east-1.amazonaws.com/api/save_listing', {
method: 'post',
body: JSON.stringify(listing)
}).then(function(response) {
return response;
});
}
console.log(listing) 产生
如何在 ReactJS 上使用端点,似乎我没有正确传递对象。现在没有任何东西写入数据库,我得到一个未定义的响应。我也得到了 415 响应。
先感谢您。
JSON.stringify(listing)
产生:
{"sku":"OX-PFWI-BNV0","account":"AO","asin":"","cogl":-5.09,"cogs":0,"status":"","launch_date ":"NULL","per_item_on_hand_rate":0,"selling_price":0,"expected_fulfillment_fee_per_unit":0,"rating":0,"picture_count":0,"amz_status":"","fba_fee":0," item_volume":"NULL","product_size_tier":"","volume_rate":"NULL","country":"USA","manager":"NULL","sub_category":"NULL"}
如果我使用邮递员发帖:
和标题: