想知道是否有人指出我在尝试将外部API请求拉入应用程序时Chrome在哪里写错代码
zone.js:3243跨域读取阻止(CORB)阻止了MIME类型为application / json的跨域响应https://seo.unamo.com/api/v1/?token=xxxxxx。有关更多详细信息,请参见https://www.chromestatus.com/feature/5629709824032768。
使用正确的令牌,如果直接在Chrome中使用Curl或Access,则JSON数据将正确显示。但是,当我尝试加载应用程序时,存在跨源阻止问题。
以下是我服务的一部分。
export class UnamoService {
url: string = this.appConfig.Unamo_URL + 'api/v1/';
constructor(private httpClient: HttpClient, public appConfig: AppConfig) { }
getRecentPositions(): Observable<any> {
return this.httpClient.get(this.url + "?token=" + this.appConfig.Unamo_Token ).pipe(
map((positions: Position[]) => {
return positions.map(() => new Position());
}),
catchError(error => {
return Observable.throw('Something went wrong ;)');
})
);
}
}
在页面上。ts
export class PositionsPage {
private positions : Position[] = [];
constructor(
public loadingController: LoadingController,
private unamo: UnamoService,
public navCtrl: NavController,
public router: Router,
public userService: UserService,
public modalView: ModalController) { }
async ngOnInit() {
const loading = await this.loadingController.create({
message: 'Please wait...',
spinner: 'crescent',
duration: 2000
});
await loading.present();
this.loadPositions().subscribe(res => {
this.positions = [...this.positions, ...res];
loading.dismiss();
});
}
loadPositions() {
return this.unamo.getRecentPositions();
}