Tôi đang cố gắng gửi yêu cầu HTTP GET từ ứng dụng Angular2/ionic2 của mình bằng cách sử dụng http.get
. Yêu cầu HTTP GET chứa một mã thông báo truy cập Linkedin hợp lệ và được cho là trả về một số profiledata. Tuy nhiên, các lỗi sau xảy ra khi getProfileData()
được gọi là:Góc 2: Ngoại lệ: Phản hồi với trạng thái: 0 cho URL: null
3 229881 group EXCEPTION: Response with status: 0 for URL: null
4 229895 error EXCEPTION: Response with status: 0 for URL: null
5 229909 groupEnd
6 229950 error Uncaught Response with status: 0 for URL: null, http://192.168.178.49:8100/build/js/app.bundle.js, Line: 95774
Tuy nhiên:
- Yêu cầu GET với cùng một URL công trình khi thử nghiệm trên www.hurl.it
- Các yêu cầu GET gọi từ ứng dụng hoạt động với một URL khác, ví dụ
let URL = "https://httpbin.org/get?name=hannes"
nhập môn-load.ts:
import { Component } from '@angular/core';
import { NavController, Platform, Alert } from 'ionic-angular';
import { OnboardingHelloPage } from '../onboarding-hello/onboarding-hello';
import { CordovaOauth, LinkedIn } from 'ng2-cordova-oauth/core';
import { Http, Headers, RequestOptions } from '@angular/http';
import 'rxjs/add/operator/map'
@Component({
templateUrl: 'build/pages/onboarding-load/onboarding-load.html',
})
export class OnboardingLoadPage {
private data;
private code;
constructor(private navCtrl: NavController, private platform: Platform, private http: Http) {
this.http = http;
this.navCtrl = navCtrl;
}
public getProfileData() {
let URL = "https://api.linkedin.com/v1/people/~?oauth2_access_token=SOMEVALIDTOKEN&format=json";
//let URL = "https://httpbin.org/get?name=hannes"
this.http.get(URL)
.map(res => res.json())
.subscribe(data => {
this.data = data;
console.log(JSON.stringify(data));
});
// go to next page
this.viewOnboardingHello();
}
...
}
Có cùng vấn đề. điều này cực kỳ khó chịu. Vì vậy, chức năng cơ bản không hoạt động và bao gồm các trường hợp tầm thường – Roman
cần sửa chữa cho – user2320607
Khi sự cố này xảy ra với sự cố CORS, – LeRoy