как обойти CORB в хроме с помощью ионного - PullRequest
0 голосов
/ 19 февраля 2019

когда я вызываю логин API, я получаю Блокировка перекрестного чтения (CORB) заблокировала ответ перекрестного происхождения с приложением MIME-типа / json , и я не могу аутентифицировать пользователя всякий раз, когдая пытаюсь войти в систему пользователя, CORB блокирует мой http-запрос, и я не могу аутентифицировать пользователя. Я новичок в ionic, поэтому я не могу устранить эту ошибку, любая помощь будет оценена

  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)

1 Ответ

0 голосов
/ 21 февраля 2019

Возможный дубликат: Chrome 'Блокировка перекрестного происхождения (CORB) блокирует ответ перекрестного происхождения' ionic

В любом случае ...

Вам необходимо добавить несколькоЗаголовок CORS в вашем ответе API.

Мой бэкэнд в PHP, поэтому я просто добавил следующие строки:

header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Access-Control-Allow-Headers: Content-Type');
...