401 status error on API request

Multi tool use


401 status error on API request
I always get this error when trying to implement simple web service that displays just a msg (angular5 + spring boot)
this is the error
:vendor.bundle.js:62557 ERROR HttpErrorResponse {headers: HttpHeaders,
status: 401, statusText: "OK", url: "localhost:8080/hello";, ok:
false, …} error : "... headers : HttpHeaders
{normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} message :
"Http failure response for localhost:8080/hello: 401 OK" name :
"HttpErrorResponse" ok : false status : 401 statusText : "OK" url :
"localhost:8080/hello";
this is my simple code:
controller.java:
@GetMapping("/hello")
public String sayhello(){ return "{"message": "Hello, world!"}";}
}
hello.component.ts:
import { Component, OnInit } from '@angular/core';
import { HttpClient, HttpErrorResponse, HttpParams } from '@angular/common/http';
import { Observable } from 'rxjs/Rx';
import { Adresse } from '../shared/adresse';
@Component({
selector: 'app-forgot', templateUrl: './forgot.component.html',
styleUrls: ['./forgot.component.css']
})
export class ForgotComponent implements OnInit {
message: string;
ip: string = Adresse.ip;
constructor(private http: HttpClient) { }
ngOnInit(): void {
this.http.get(this.ip + '/hello').subscribe(data => {
console.log('DATA', data);
this.message = data['message'];
})
}
}
this is the error :vendor.bundle.js:62557 ERROR HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "OK", url: "localhost:8080/hello", ok: false, …} error : "<!doctype html>... headers : HttpHeaders {normalizedNames: Map(0), lazyUpdate: null, lazyInit: ƒ} message : "Http failure response for localhost:8080/hello: 401 OK" name : "HttpErrorResponse" ok : false status : 401 statusText : "OK" url : "localhost:8080/hello"
– Vectorya
14 mins ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
1st: Dont post images of errors/ stacktraces. Copy them from your console into here. 2nd: Can you post your spring-security config please?
– mrkernelpanic
17 mins ago