在最新版本中进行CORS操作的正确生产方式是什么?
我的功能:
public fetchData() {
console.log("GET WITH HEADERS");
return this.http.get('http://192.168.31.73:8080/myjersey/rest/hello/dd').map(
(response) => response
)
.subscribe(
(data) => console.log(data)
)
}
public authentication(email, password) {
console.log("POST WITH HEADERS");
const body = { name: 'Brad' };
this.http
.post('http://192.168.31.73:8080/myjersey/rest/hello/dd', {
email: email,
password: password
}, {
headers: new HttpHeaders().set('Access-Control-Allow-Origin', '*')
.set('Access-Control-Allow-Credentials', 'true')
.set('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE')
.set('Access-Control-Allow-Headers', 'X-Custom-Header'),
})
.subscribe();
}
下面的是我得到的例外:
Failed to load http://192.168.31.73:8080/myjersey/rest/hello/dd: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access.
不知怎的,我的Http Get正在工作,但没有POST.Please建议在这种情况下我应该做什么我在请求和响应中添加了Access-Control-Allow-Origin仍然会收到CORS问题。
PS:我不懂PHP。我正在使用带角度的泽西休息服务。