json - 带有 JSON 参数的 Typescript Rest API POST 调用
问题描述
我正在尝试找到一个代码示例,以使用 as 参数向 Api发送POST
请求,并在 Typescript 中获取响应和任何异常/错误代码。REST
JSON
解决方案
你可以从这样的事情开始
服务
export class MyService{
constructor(
private httpClient: HttpClient) {
}
getSomethingFromServer():Observable<any>{
return this.httpClient.get('you_request_url');
}
}
零件
constructor(
private myService: MyService) {
}
this.myService.getSomethingFromServer().subscribe(response => {
// do whatever you want with the response
}, error => {
// handle error here
// error.status to get the error code
});
推荐阅读
- php - 我如何允许自定义标签和属性 html?
- php - Symfony 没有生成 Bundle
- javascript - 如何切换导航栏可见性?
- javascript - 如何使用 javascript 将 div 内容镜像/复制到表单字段中
- c# - 将不断读取的串行缓冲区数据传递给另一个类的问题
- r - 如何从R中的函数dose.p(包MASS)中提取SE?
- google-cloud-firestore - 将 Firestore CRUD 限制为特定域中的用户
- django - Django URL 模式已停止匹配
- gitlab - gitlab-runner 在查询作业时偶尔会收到 403“禁止访问”
- azure - BotBuilderFramwork:无法初始化 - Microsoft.WindowsAzure.ServiceRuntime