【发布时间】:2021-10-18 21:16:57
【问题描述】:
我正在使用 js fetch 发送一个简单的 POST 请求,它被发送到 Bartender Label Software Integration Application 但它无法处理使用以下代码时发送的 OPTIONS 或 CORS Pre flight:
<script>
const TurkishDelightBrownieButton = document.getElementById('Turkish Delight Brownie');
TurkishDelightBrownieButton.addEventListener('click', function () {
fetch('http://localhost:8000/brownie', {
method: 'POST',
headers: {
'content-type': 'application/json',
},
body: {
Allergens: 'Egg, Wheat, Soya',
Ingredients: "Sugar, Butter, Cream ,stuff like that",
Flavour: "Brownie Flavoured",
DatePacked: "12/08/2021",
BestBefore: "22/08/2021"
}
})
.then(response => {
console.log(response)
})
.catch(err => {
console.log(err)
})
});
</script>
这一切都在本地完成,所以我正在尝试使请求适合 Bartender 集成 - 主要是 application/json。
如果有人对此有任何建议或不同的方法,我很乐意提供帮助!
【问题讨论】:
标签: javascript html api cors bartender