我需要设置哪些标头才能进入我的提取请求?

问题描述 投票:0回答:1

我正在尝试在 Svelte 组件中获取 Fetch 请求。如果我使用curl 和Postman,效果很好。看来我的标题可能是错误的。关于我在这里做错了什么有什么想法吗?

这是curl请求:

curl -XPOST http://127.0.0.1:8000/parse --data 'locale=en_GB&text=Monday'

这些是 Postman 中设置的标题

我的代码:

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)
    });
}
javascript fetch-api svelte
1个回答
0
投票

Content-(t)ype 中的最后一个“t”应该大写

  headers: {
    'Content-Type': 'application/x-www-form-urlencoded'
  }
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.