Apache angular 2 XMLHttpRequest无法加载预飞行的响应,因为其HTTP状态代码为400无效
已启用CORS以启用我的angular2和magento之间的请求 为此,我需要更改我的magento的apache服务器设置 我在apache的htaccess文件中添加了以下几行以启用选项请求Apache angular 2 XMLHttpRequest无法加载预飞行的响应,因为其HTTP状态代码为400无效,apache,angular,Apache,Angular,已启用CORS以启用我的angular2和magento之间的请求 为此,我需要更改我的magento的apache服务器设置 我在apache的htaccess文件中添加了以下几行以启用选项请求 Header always set Access-Control-Allow-Origin "*" Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT" Header always set Access-Co
Header always set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Methods "POST, GET, OPTIONS, DELETE, PUT"
Header always set Access-Control-Max-Age "1000"
Header always set Access-Control-Allow-Headers "x-requested-with, Content-Type, origin, authorization, accept, client-security-token"
....
Options +FollowSymLinks
RewriteEngine on
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_METHOD} OPTIONS
RewriteRule ^(.*)$ $1 [R=200,L]
RewriteRule .* - [L,R=405]
这就是我在angular 2中调用rest api的方式:
export class ProductService {
public _productUrl = 'http://10..../Mage_ang2/index.php/rest/V1/customers/1';
constructor(private _http: Http) { }
getProducts(): Observable<IProduct[]> {
let headers = new Headers({ 'Content-Type': 'application/json; charset=utf-8' });
headers.append('Authorization', 'Bearer ntthnrbj1uam2tuv1ekva7n8jh18mcnkby3');
let options = new RequestOptions( {method: RequestMethod.Get, headers: headers });
console.log(headers);
return this._http.get(this._productUrl,options)
.map((response: Response) => <IProduct[]> response.json())
.do(data => console.log('All: ' + JSON.stringify(data)))
.catch(this.handleError);
}
导出类产品服务{
公共产品http://10..../Mage_ang2/index.php/rest/V1/customers/1';
构造函数(私有http:http){}
getProducts():可观察{
let headers=new headers({'Content-Type':'application/json;charset=utf-8'});
附加('Authorization'、'Bearer ntthnrbj1uam2tuv1ekva7n8jh18mcnkby3');
let options=newrequestoptions({method:RequestMethod.Get,headers:headers});
console.log(头文件);
返回此.\u http.get(此.\u产品URL,选项)
.map((response:response)=>response.json())
.do(data=>console.log('All:'+JSON.stringify(data)))
.接住(这个.把手错误);
}
如果我运行angular2,我会得到:
无法加载XMLHttpRequest。飞行前的响应具有无效的HTTP状态代码400
使用上述设置从其他域获取对我的CORS的响应的正确方法是什么