访问此资源需要401完整身份验证 [英] 401 full authentication is required to access this resource

查看:153
本文介绍了访问此资源需要401完整身份验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图从我的本地API服务器中使用get请求来检索json数据。我总是收到这个错误。我已经访问过很多网站,但我还没有找到解决这个问题的方法。
有人知道为什么以及如何解决它?如果需要更多的配置信息,请告诉我,谢谢

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());
    }
}


推荐答案

I找到解决方案,我把标题的授权;它工作正常!
让我们看看这里的解决方案:

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);
    } 

这篇关于访问此资源需要401完整身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆