【发布时间】:2017-01-24 00:24:34
【问题描述】:
我正在尝试使用 http.get 从我的 Angular2/ionic2 应用程序发送 HTTP GET 请求。 HTTP GET 请求包含一个有效的 Linkedin 访问令牌,并且应该返回一些配置文件数据。但是在调用getProfileData()时会出现如下错误:
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
仍然:
- 在 www.hurl.it 上测试时,具有相同 URL 的 GET 请求有效
- 从应用程序调用的 GET 请求使用不同的 URL,例如
let URL = "https://httpbin.org/get?name=hannes"
入职加载.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();
}
...
}
【问题讨论】:
-
有同样的问题。这非常烦人。所以基本功能不起作用并涵盖微不足道的情况
-
需要解决这个问题
-
发生此问题时,通常是 CORS 问题,