我正嘗試使用http.get
從我的Angular2/ionic2應用發送HTTP GET請求。 HTTP GET請求包含有效的Linkedin訪問令牌,應該返回一些profiledata。然而,當getProfileData()
被稱爲出現以下錯誤:Angular 2:EXCEPTION:狀態響應:0表示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
還有:
- 用相同的URL的GET請求時,在www.hurl.it
- GET請求從被稱爲測試工程該應用使用不同的網址,例如
let URL = "https://httpbin.org/get?name=hannes"
職-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();
}
...
}
有同樣的問題。這非常煩人。所以基本功能不起作用,涵蓋微不足道的情況 – Roman
需要修復此 – user2320607
當發生此問題時,它通常是一個CORS問題, – LeRoy