如何使用离子去除铬中的CORB

问题描述 投票:0回答:1

当我调用login api时,我发现跨源读取阻塞(CORB)阻止了与MIME类型application / json的跨源响应,并且每当我尝试登录用户时,我无法验证用户CORB阻止我的http请求,我可以验证用户身份。我是离子新手,所以我无法解决此错误,任何帮助将不胜感激

  if (this.plugins.isOnline()) {
            if (this.wait == true) {
                return;
            } else if (this.userLogin.email == '' || this.userLogin.password == '') {
                this.utility.doToast("Please don't leave any field blank.");
                return;
            } else {
                this.wait = true;
                // this.getRequiremensts();
                this.auth.login(this.userLogin).subscribe((success) => {
                    this.wait = false;
                    console.log("loginData",success.successData);
                    this.credential.setUser(success.successData);
                    // this.plugins.sendTags(success.successData.id);
                    this.rememberUsertype(success.successData.is_celebrity);
                    if(success.successData.is_celebrity == '0'){
                    this.app.getRootNav().setRoot("HomePage");
                    }
                    else if(success.successData.is_celebrity == '1'){
                    this.app.getRootNav().setRoot("DashboardPage");
                     }

                    }, (error) => {
                        console.log(error);
                    this.wait = false;
                    if (this.utility.timeOutResponse(error))
                        this.utility.doToast("The email or password you entered is incorrect.")
                })
            }
        } else {
            this.utility.doToast(this.utility.internetConnectionMessage());
        }



login(params) {

        var url = this.constants.API_ENDPOINT + 'login';
        var response = this.http.post(url, params, {}).map(res => res.json());
        return response;
    }


 if (options == null) {
            options = new RequestOptions();
        }
        if (options.headers == null) {
            options.headers = new Headers();
        }
        options.headers.append('app_key', 'Some App Key');

        var _token = localStorage.getItem('token');
        if (_token)
            options.headers.set('session_token', _token);

        options.headers.set("Cache-Control", "no-cache");

        return options; 
    }

错误

SyntaxError: Unexpected end of JSON input
    at JSON.parse (<anonymous>)
    at Response.Body.json (http.js:1091)
    at MapSubscriber.project (auth.service.ts:29)
    at MapSubscriber._next (map.js:79)
    at MapSubscriber.Subscriber.next (Subscriber.js:93)
    at CatchSubscriber.Subscriber._next (Subscriber.js:129)
    at CatchSubscriber.Subscriber.next (Subscriber.js:93)
    at TimeoutSubscriber.Subscriber._next (Subscriber.js:129)
    at TimeoutSubscriber._next (timeout.js:132)
    at TimeoutSubscriber.Subscriber.next (Subscriber.js:93)
angular ionic-framework ionic2 ionic3
1个回答
0
投票

可能重复:Chrome' Cross-Origin Read Blocking (CORB) blocked cross-origin response' ionic

无论如何...

您需要在API响应中添加一些CORS标头。

我的后端是PHP,所以我只是添加了这个字符串:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type');
© www.soinside.com 2019 - 2024. All rights reserved.