我遇到了一个我不明白的问题。我尝试使用以下代码在表单中将数据发布到我的API
formSubmit() {
const req =this.http.post('http://[ip]/api/login', {
id: '7',
username: 'PostTest',
password: 'studp123lan',
matrikelnr: 'winf303666',
email: '[email protected]',
email_verified: '1'
})
.subscribe(
res => {
console.log(res);
},
err => {
console.log("Error occured");
}
当我在Chrome开发者工具中检查它时,这就是我得到的:
Failed to load http://[ip]/api/login: Response for preflight has
invalid HTTP status code 404
register.component.ts:42 Error occured
这就是我在网络标签中得到的:
一般:
Request URL:http://[ip]/api/login
Request Method:OPTIONS
Status Code:404 Not Found
Remote Address:[ip]:80
Referrer Policy:no-referrer-when-downgrade
响应标题:
Access-Control-Allow-Headers:Content-Type
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS
Access-Control-Allow-Origin:*
Content-Length:0
Date:Thu, 21 Dec 2017 09:00:35 GMT
Server:Kestrel
X-Powered-By:ASP.NET
请求标题:
Accept:*/*
Accept-Encoding:gzip, deflate
Accept-Language:de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7
Access-Control-Request-Headers:content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:[ip]
Origin:http://localhost:4200
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/63.0.3239.108 Safari/537.36
不知何故,这不起作用。但是当我通过Postman Post Request将相同的数据发布到同一个URL时,它就像一个魅力。谁能解释和帮助?谢谢。
404是未找到页面错误:这表示您的端点在此地址不可用。
当然,你打了一个邮差,它可以工作:但你是手工制作邮差,还是使用拦截器制作它? (拦截器是一个Chomr插件,允许您将Chrome发出的所有呼叫注册到邮递员中)。
必须有一些你忘记的东西。你可以发贴邮差,如果可以,试试拦截器吗?