Angular5 + HTTP通过HTTP基本身份验证获取请求获得401错误

时间:2020-02-05 11:19:04

标签: angular spring-boot angular6 basic-authentication

I am trying to access a URL with Basic Authentication.

My URL will return String 

How can I add my username and password to this http request below?

**尝试如下:**

headers :any;
 getVersionAPI() {
    const httpOptions = {
      headers: new HttpHeaders({
       'Content-Type':  'application/json',
        'Authorization': 'Basic ' + btoa('username:password')
      })
    };
   return this.Http.get(this.global.baseURL+this.global.getApiVersion,this.httpOptions).map((res: Response) => res.json());
  }
 getVersion(){
    this.getVersionAPI().subscribe(data => {
      this.apiVersion=data;
    });
  }

Getting 401 error code.
My rest authentication Configuration is as follows:

'受保护的void configure(HttpSecurity http)引发异常{ http.httpBasic()。and()。authorizeRequests()。antMatchers(“ / api / **”)。hasRole(“ USER”)。and() .csrf()。disable()。headers()。frameOptions()。disable(); http.httpBasic()。authenticationEntryPoint(authEntryPoint); }'

0 个答案:

没有答案
相关问题