【发布时间】:2021-01-02 05:07:51
【问题描述】:
考虑到文档向您展示了这一点,您将如何提出此发布请求
POST /cf HTTP/1.1
Host: apis.woptima.com
Content-Type: application/json
{
"name": "franco",
"surname": "Baldi",
"gender": "M",
"day": 22,
"month": 12,
"year": 1980,
"city": "Roma",
"province": "RM"
}
我尝试了我的方法,但没有成功,我得到 validationError 422
fetch("https://cors-anywhere.herokuapp.com/https://apis.woptima.com/cf", {
headers: {
Accept: "application/json",
"Content-Type": "application/json",
},
method: POST,
// I also tried with the body object, didn't work
name: "franco",
surname: "Baldi",
gender: "M",
day: 22,
month: 12,
year: 1980,
city: "Roma",
province: "RM",
})
.then(function (response) {
return response.json()
})
.then(function (data) {
console.log(data)
})
}
如果你能帮助我,我将不胜感激
【问题讨论】:
-
method: POST,==>method: "POST", -
您应该始终打开开发者工具并检查 console 选项卡是否有错误
-
我会试试阿隆谢谢
-
我现在收到此错误 Access to fetch at 'apis.woptima.com/cf' from origin 'prolocofraine.netlify.app' 已被 CORS 策略阻止:对预检请求的响应没有' t 通过访问控制检查:请求的资源上不存在“Access-Control-Allow-Origin”标头。如果不透明的响应满足您的需求,请将请求的模式设置为“no-cors”以获取禁用 CORS 的资源
标签: javascript post promise fetch