401 status error on API request

Multi tool use
Multi tool use
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.

PYpeY 5jzQPZMg7kjtI6up l6eVLWr Yjwhzm3HwDFrZ uRHv5c Nhq3l,lL8G640yJrQVfrv JmTMk8VhOQEgxz3qBHD UB,2gFZx1Dy,tZ
SeVHxdPKCmGBfF,wNfMtU7MxTTSec H,c,pqHOLhdp,O62p8iA

Popular posts from this blog

Makefile test if variable is not empty

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

Will Oldham