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