Angular5 + HTTP Получить запрос с аутентификацией HTTP-Basi c, получая ошибку 401 - PullRequest
1 голос
/ 05 февраля 2020
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:

'Защищенная пустота (HttpSecurity http) создает исключение {http.httpBasi c (). И (). AuthorizeRequests () .antMatchers ("/ api / **"). hasRole ("USER"). и () .csrf (). disable (). headers (). frameOptions (). disable (); http.httpBasi c () AuthenticationEntryPoint (authEntryPoint). } '

...