angular - 为什么 Chrome DevTool Network 在 aspnetboilerplate 的 angular4 项目中有两个相同的请求?
问题描述
在开发 angular4 项目时,我在 chrome devtool 网络中发现了两个相同的请求。下面是http请求的代码: 注:以上代码是使用nswag生成的。
userApplyLimitAsync(): Observable<GetUserApplyLimitOutput> {
let url_ = this.baseUrl + "/api/services/app/AElfApplication/UserApplyLimitAsync";
url_ = url_.replace(/[?&]$/, "");
let options_ = {
method: "post",
headers: new Headers({
"Content-Type": "application/json",
"Accept": "application/json"
})
};
return this.http.request(url_, options_).flatMap((response_) => {
return this.processUserApplyLimitAsync(response_);
}).catch((response_: any) => {
if (response_ instanceof Response) {
try {
return this.processUserApplyLimitAsync(response_);
} catch (e) {
return <Observable<GetUserApplyLimitOutput>><any>Observable.throw(e);
}
} else
return <Observable<GetUserApplyLimitOutput>><any>Observable.throw(response_);
});
}
protected processUserApplyLimitAsync(response: Response): Observable<GetUserApplyLimitOutput> {
const status = response.status;
let _headers: any = response.headers ? response.headers.toJSON() : {};
if (status === 200) {
const _responseText = response.text();
let result200: any = null;
let resultData200 = _responseText === "" ? null : JSON.parse(_responseText, this.jsonParseReviver);
result200 = resultData200 ? GetUserApplyLimitOutput.fromJS(resultData200) : new GetUserApplyLimitOutput();
return Observable.of(result200);
} else if (status !== 200 && status !== 204) {
const _responseText = response.text();
return throwException("An unexpected server error occurred.", status, _responseText, _headers);
}
return Observable.of<GetUserApplyLimitOutput>(<any>null);
}
下面是函数的调用代码userApplyLimitAsync()
:
this._withdrawService.userApplyLimitAsync()
.subscribe((result) => {
this.withdrawActive = result.isSucceed;
});
userApplyLimitAsync()
是 的成员WithdrawServiceProxy
,并且_withdrawService
是 的实例WithdrawServiceProxy
。当我调用时userApplyLimitAsync()
,为什么它会创建两个相同的请求?
两个相同的请求第一个第二个
解决方案
不一样的要求。甚至不是同一个 HTTP 动词。您应该研究 HTTP 动词,主要是 OPTIONS 和 POST。
推荐阅读
- excel - 添加第三个系列时出现参数无效错误
- django - Django Okta 集成
- c++ - 为什么这个方法会进入无限循环?
- python - 如何在python中旋转Y轴
- ios - 如何以编程方式设置约束加常量?
- python - 有没有办法将加载的 excel 文件和变量保存在内存中以节省时间?
- python - 从 json 字符串中读取数据并使用 python 对其进行操作
- node.js - “可能不会将空值写入流”写入 pdftotext 的 node.js 子进程的标准输入
- node.js - 节点的异步行为是否会给拍卖/电子商务网站带来问题
- python - 将映射对象转换为具有四个变量的已定义函数的值