401 status error on API request

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


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





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





this is the error :vendor.bundle.js:62557 ERROR HttpErrorResponse {headers: HttpHeaders, status: 401, statusText: "OK", url: "localhost:8080/hello&quot;, 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&quot;
– 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.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Blogger: Contempo template have managed to get the posts to post in full but there is still a “snippet” of the post at the bottom of each full post