问题
i'm trying to retrieve json data from my local API Server, using get request. I always receive this error. I already visit many sites, but i haven't find solution to this problem. Does anybody know why and how to fix it? If it's needed more configuration information, let me know, thanks
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());
}
}
回答1:
I found the solution, i put an authorization on the headers; and it works fine! let see the solution here:
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);
}
来源:https://stackoverflow.com/questions/36355787/401-full-authentication-is-required-to-access-this-resource