我正在尝试在 Svelte 组件中获取 Fetch 请求。如果我使用curl 和Postman,效果很好。看来我的标题可能是错误的。关于我在这里做错了什么有什么想法吗?
这是curl请求:
curl -XPOST http://127.0.0.1:8000/parse --data 'locale=en_GB&text=Monday'
我的代码:
function handleClick() {
const url = "http://127.0.0.1:8080/parse"
fetch(url, {
mode: 'no-cors',
method: "POST",
headers: { 'Content-type': 'application/x-www-form-urlencoded'},
data: new URLSearchParams({
locale: "en_GB",
text: "Monday"
})
})
.then(console.log("test"))
.then((response) => {
console.log(response);
response.json().then((data) => {
console.log("data");
})
})
.catch((error) => {
console.log(error)
});
}
Content-(t)ype 中的最后一个“t”应该大写
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}