2016-04-01 10 views
1

get requestを使用してローカルAPIサーバからjsonデータを取得しようとしています。私はいつもこのエラーを受け取ります。私はすでに多くのサイトを訪れていますが、私はこの問題の解決策を見出していません。 なぜ誰かがそれを修正する方法を知っていますか?より多くの設定情報が必要な場合は、お知らせください。このリソースにアクセスするには401フル認証が必要です

import {Injectable} from 'angular2/core'; 
import {Http} from "angular2/http"; 
import 'rxjs/add/operator/map'; 
import 'rxjs/Rx'; 
import {Headers} from "angular2/http"; 
import {Jsonp} from "angular2/http"; 

@Injectable() 
export class HTTPTestService{ 
    constructor(private _http: Http){} 

getCurrentTime(){ 

     console.log('je suis le test0'); 
     console.log(this._http.get('http://localhost:9090/webservices/pivot/rest/v1/cube/discovery').map(res => res.json())); 
     console.log('je suis le test10'); 
    return this._http.get('http://localhost:9090/webservices/pivot/rest/v1/cube/discovery') 
      .map(res => res.json()); 
    } 
postJSON(){ 
     var json=JSON.stringify({var1: 'test', var2: 3}); 
     var params = 'json=' + json; 
     var headers = new Headers(); 
     headers.append('Content-Type', 'application/x-www-form-urlencoded'); 
     return this._http.post('http://jsonplaceholder.typicode.com/posts', 
      params,{ 
       headers: headers 
      }) 
      .map(res => res.json()); 
    } 
} 

答えて

2

私は解決策を見つけました。それはうまく動作します! ここに解決策を見てください:

getCurrentTime(){ 
     console.log('je suis le test0'); 
     var headers = new Headers(); 
     headers.append('Authorization', 'Basic YWRtaW46YWRtaW4='); 

     return this._http 
      .get('http://localhost:9090/webservices/pivot/rest/v1/cube/discovery', {headers: headers}) 
      .map(res => res.json().data); 
    } 
関連する問題