Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/29.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular IONAL-被CORS策略阻止:无“访问控制允许来源”_Angular_Typescript_Cors_Ionic4 - Fatal编程技术网

Angular IONAL-被CORS策略阻止:无“访问控制允许来源”

Angular IONAL-被CORS策略阻止:无“访问控制允许来源”,angular,typescript,cors,ionic4,Angular,Typescript,Cors,Ionic4,我创建了一个Ionic应用程序,该应用程序连接到一个API网站,为了保护目的,我将我的网站连接到CloudFlare,在此之前,我启用了攻击模式,请求在该模式下完美地发送,没有任何错误,但现在它在控制台中显示了一个错误,显示: 访问位于“”的XMLHttpRequesthttps://mywebsite.org/api/mobile/news?pageSize=15¤tPage=1&language=undefined“起源”http://localhost:8100'已被CORS

我创建了一个Ionic应用程序,该应用程序连接到一个API网站,为了保护目的,我将我的网站连接到CloudFlare,在此之前,我启用了攻击模式,请求在该模式下完美地发送,没有任何错误,但现在它在控制台中显示了一个错误,显示:

访问位于“”的XMLHttpRequesthttps://mywebsite.org/api/mobile/news?pageSize=15¤tPage=1&language=undefined“起源”http://localhost:8100'已被CORS策略阻止:对飞行前请求的响应未通过访问控制检查:请求的资源上不存在'access control Allow Origin'标头。

后端是flask micro服务,我还启用了cors角色

cors.init_appapp,资源={rhttps://mywebsite.org/api/*:{来源:https://mywebsite.org}}

每次我从应用程序发送get请求时,我也会在标题中添加一个访问控制允许来源:

let headers = new HttpHeaders({
    "Access-Control-Allow-Origin":"https://mywebsite.org/",
    "origin":"https://mywebsite.org/"
});

@Injectable({
    providedIn: 'root'
})
export class DataApiService {

    private apiUrl: string = 'https://mywebsite.org/api';


    constructor(
    private http: HttpClient,
    private translate: TranslateService
    ) { }

    // Get news
    apiRequest(url: string, params?:any){

    const apiUri = `${this.apiUrl+url}`;

    if(params){
        params.language = this.translate.getDefaultLang();
    }

    return this.http.get(apiUri, { headers: headers, params: params }).pipe(
        delay(
        500
        ),
        map(
        (res:any) => {
            return res
        }
        )
    )
    }
}
请帮忙。

看这个

您必须添加主机而不是本地主机-host test.test.co

然后转到本地磁盘

移到这里C:\Windows\System32\drivers\etc

然后修改您的主机文件

127.0.0.1 test.test.co

sry不擅长英语


我希望这有助于

当localhostwill我看到时,一些浏览器阻止cors请求,chrome正在破坏请求一些如何,不要紧,你的回答帮助了我,谢谢