我在http://ionicapp-api.co.nf/api托管了一个简单的API,并且想从离子应用程序访问一个端点,在http://ionicapp.co.nf托管了一个端点,我试图从该应用程序内部访问该端点,但我无法使其正常工作,我始终会收到301响应。但是,当我尝试从任何浏览器访问相同的端点时,都会从API中获得正确的答案。
任何人都可以帮助解决该问题,我在代码中尝试了很多已经搞砸的事情,希望你们能理解。
正在尝试访问端点的代码。
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Storage } from '@ionic/storage';
@Injectable()
export class MesasProvider {
private URL_API = 'http://ionicapp-api.co.nf/api/';
constructor(public http: HttpClient, public storage: Storage) {
console.log('Hello MesasProvider Provider');
}
listar() {
return new Promise((resolve, reject) => {
console.log(this.URL_API + 'mesas/');
const httpOptions = {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': 'http://ionicapp.co.nf',
})
};
this.http.get(this.URL_API + 'mesas/', httpOptions)
.subscribe((result: any) => {
console.log(result);
resolve(result)
},
(error: any) => {
reject(error)
});
/*
this.storage.get('token')
.then((token: string) => {
const httpOptions = {
headers: new HttpHeaders({
'Access-Control-Allow-Origin': '*',
'Accept': 'application/json',
'Authorization': 'Bearer ' + token,
})
};
this.http.get(this.URL_API + 'mesas/')//, httpOptions)
.subscribe((result: any) => {
console.log(result);
resolve(result)
},
(error: any) => {
reject(error)
})
})
.catch((error) => {
console.log(error);
});*/
});
}
}