加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Angular 2:EXCEPTION:响应状态:URL为0:null

发布时间:2020-12-17 07:51:50 所属栏目:安全 来源:网络整理
导读:我正在尝试使用http.get从我的Angular2 / ionic2应用程序发送HTTP GET请求. HTTP GET请求包含有效的Linkedin访问令牌,并且应该返回一些profiledata.但是,调用getProfileData()时会发生以下错误: 3 229881 group EXCEPTION: Response with status: 0 for URL
我正在尝试使用http.get从我的Angular2 / ionic2应用程序发送HTTP GET请求. HTTP GET请求包含有效的Linkedin访问令牌,并且应该返回一些profiledata.但是,调用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,例如让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();
}
...
}
这可能是一个CORS问题.
您的Angular2 APP托管在您正在呼叫的API之外的其他服务器上.

如果要绕过此(仅用于测试目的),请安装this Chrome extension并添加

Access-Control-Allow-Origin:

到你的标题.对于实际使用,您应该从您的服务器(Node,PHP,Python …)(托管angular2 APP)调用API,并将数据传递给angular2 APP.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读