【发布时间】:2020-01-20 23:16:56
【问题描述】:
我正在尝试通过 Angular-Cli 发送 GET 请求。 这是我的尝试:
constructor(private http: HttpClient) {}
getFirst(){
this.http.get('localhost:3000/update_first').subscribe((data) => console.log(data));
}
这会在控制台中出现错误:
Http failure response for localhost:3000/update_first: 0 Unknown Error
所以我检查了服务器是否收到了消息 - 它没有。
我尝试了 curl (curl 'localhost:3000/update_first') 的相同请求,它成功了。所以,由于某种原因,角度似乎没有发送请求。
我有什么遗漏吗?
【问题讨论】:
-
您缺少协议。
localhost:3000/update_first应该是http://localhost:3000/update_first或https://localhost:3000/update_first。 -
@R.Richards 哦。现在我遇到了同样的错误,但有一个警告:
Cross-Origin Request Blocked。我想这就是问题所在。谢谢
标签: javascript node.js angular typescript http