angular - 响应状态代码为空
问题描述
我在 Angular 7 中实现了 post 方法。我想要 post 请求的状态代码。
我做了以下。
const sub = this.service.regEvent(this.pId, this.email)
.subscribe(response => {
console.log('response:', response);
if(response.httpStatusCode === 200) {
}
});
this.subscriptions.push(sub);
注册事件方法
public regEvent(pId, email): Observable<any> {
return this.http.post<any>(`this.endpointUrl?eventId=${pId}&email=${email}`,"").pipe(
catchError(this.handleError)
);
}
在这里console.log('response:', response);
我得到空值。
在浏览器中我检查了它。
在邮递员也。
任何帮助将不胜感激。
解决方案
您将需要观察响应,例如
this.http.post<any>(`this.endpointUrl?eventId=${pId}&email=${email}`,"",{observe: 'response'})
推荐阅读
- scala - 改进逻辑以在给定的 string1 上查找循环旋转可以产生 string2
- java - DynamoDBLocal 测试中的错误:com.almworks.sqlite4java.SQLiteException:[-91] 无法加载库:java.lang.UnsatisfiedLinkError
- python - InvalidBSON 消耗游标并引发 StopIteration。如何跳过坏文档?
- vue.js - Vuetify 验证只返回 false 并且无法正常工作
- python - Pytest在使用参数化时测试KeyError异常
- javascript - 将 React 上下文变量作为道具传递与直接在功能组件中使用
- javascript - 单击链接时关闭导航覆盖(一个寻呼机)
- groovy - 是将 Groovy 闭包转换为 RxJava 可以使用的形式的正确方法
- reactjs - Material-UI 大纲输入标签不正确对齐
- java - 对java非常陌生,没有找到主要类。