我正在尝试使用 HttpClient 发送发布请求。
constructor (private http: HttpClient) { }
this.http.post(url + 'auth/login', data).subscribe(res => { });
但是浏览器发送了 4 个请求而不是一个 POST 请求:
我读过它被称为“预检请求”https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS#Preflighted_requests
我收到 405 Method Not Allowed
错误,因为服务器不支持此路径 The GET method is not supported for this route. Supported methods: POST.
不幸的是,我无法修改服务器以接受 GET 请求,无论如何我可以阻止浏览器发送 GET 请求?
提前致谢。
答案 0 :(得分:0)
我发现这只发生在“http://”上。
我试过“https://”并且它工作正常:)