我在angular2中使用自定义标头"CLIENT-ID":"company"
,后端使用jax rs。我在后端服务器中修复了Access-Control-Allow-Headers
和所有CROS
相关问题,如果我使用postman工作查找但是当我尝试使用角形式访问时,它给了我一个问题
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8080/parkgarau-ws/rest/login. (Reason: missing token ‘client-id’ in CORS header ‘Access-Control-Allow-Headers’ from CORS preflight channel).
我不知道是什么问题,在服务器client-id中返回null并提供没有响应主体的选项respoonse 200
这是我的角度代码
login(loginUser: LoginUser) {
console.log(JSON.stringify(loginUser));
console.log(UrlConfig.BASE_URL + UrlConfig.LOGIN);
return this._http.post(
UrlConfig.BASE_URL + UrlConfig.LOGIN,
JSON.stringify(loginUser),
this.getHeaderInfo(loginUser.companyCode)
)
.map((response: Response) =>
response.json()
);
}
private getHeaderInfo(companyCode: string) {
let headers = new Headers(
);
headers.append("CLIENT-ID",companyCode);
headers.append("Content-Type", "application/json");
headers.append("Accept", "application/json");
console.log(headers);
return new RequestOptions({ headers: headers });
}
这是我的http请求和响应
Request URL:http://192.168.0.108:8080/parkgarau-ws/rest/login
Request Method:OPTIONS
Status Code:200
Remote Address:192.168.0.108:8080
Response Headers
view source
Access-Control-Allow-Credentials:true
Access-Control-Allow-Headers:origin,accept,content-type
Access-Control-Allow-Methods:GET, POST, PUT, DELETE, OPTIONS, HEAD
Access-Control-Allow-Origin:*
Access-Control-Max-Age:151200
Allow:POST,GET,PUT,OPTIONS,HEAD
Content-Length:0
Date:Thu, 16 Feb 2017 16:00:53 GMT
Server:Apache TomEE
x-responded-by:cors-response-filter
Request Headers
view source
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Access-Control-Request-Headers:access-control-allow-origin, client-id, content-type
Access-Control-Request-Method:POST
Connection:keep-alive
Host:192.168.0.108:8080
Origin:http://localhost:4200
Referer:http://localhost:4200/
User-Agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.87 Safari/537.36