首页 > 解决方案 > 为什么 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(),为什么它会创建两个相同的请求? 两个相同的请求第一个第二个

标签: angularrxjsaspnetboilerplate

解决方案


不一样的要求。甚至不是同一个 HTTP 动词。您应该研究 HTTP 动词,主要是 OPTIONS 和 POST。


推荐阅读