[英]Unable to get Response from API in angular
I have created a Rest API in Java with the request Mapping(/value/generate).我在 Java 中创建了一个 Rest API 请求映射(/值/生成)。
System.out.println(value);
if(!value.equals(null)){
return new ResponseEntity(value, HttpStatus.OK);
}
return new ResponseEntity(HttpStatus.FORBIDDEN);
}
Value is getting printed in Console when iam call this through postman.当我通过 postman 调用它时,值正在控制台中打印。
But i need to print this value in my Angular console.但是我需要在我的 Angular 控制台中打印这个值。
Below is code i have created in angular.下面是我在 angular 中创建的代码。
service.ts服务.ts
generatevalue(): Observable<String> {
return this.http.get('https://localhost:8080/value/generate')
Component.ts组件.ts
ngOnInit() {
this.service.generatevalue().subscribe((Response) => {
console.log(Response)
}
}
Please let me know where i went wrong.请让我知道我哪里出错了。
Your url should probably be " http://localhost:8080/value/generate ".您的 url 可能应该是“ http://localhost:8080/value/generate ”。 Did you check your console for errors?
你检查你的控制台是否有错误? It should print an error 404 somewhere.
它应该在某处打印错误 404。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.