我的Ioinc 4在chrome和firefox浏览器上运行,但是cors在android 9上无法正常工作。我的Http标头在下面。
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
常量令牌= localStorage.getItem('access_token'); this.loaderService.show();
if (token) {
request = request.clone({ setHeaders: {
'Authorization': token,
'Accept': 'application/json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'*',
'Access-Control-Allow-Headers': '*',
}});
} else {
request = request.clone({ setHeaders: {
'Accept': 'application/json',
'Access-Control-Allow-Origin':'*',
'Access-Control-Allow-Methods':'*',
'Access-Control-Allow-Headers': '*',
}});
}
return next.handle(request).pipe(
map((event: HttpEvent<any>) => {
return event;
}),
catchError((error: HttpErrorResponse) => {
return throwError(error);
}),
finalize(() => {
this.loaderService.hide();
}));
}
答案 0 :(得分:0)
您可以将本机http插件用于http请求,此请求会自动处理,这是一个链接:https://ionicframework.com/docs/native/http