当我试图实现只显示一条消息的简单web服务时,总是会遇到这个错误(angular5+springboot)
状态:401,状态文本:“确定”,网址:80/本地主机:你好“;,确定:
错误,}错误:“。。。标题:HttpHeaders
{normalizedNames:Map(0),lazyUpdate:null,lazyInit:}消息:
错误状态:“http401”状态确定“文本:
"80/本地主机:你好";
控制器.java:
@GetMapping("/hello")
public String sayhello(){ return "{\"message\": \"Hello, world!\"}";}
}
你好.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'];
})
}
}