Http.Request(new Request({})) 发送了两次

Http.Request(new Request({})) sent twice

我正在使用 http.Request 方法对服务器进行 http 调用。在浏览器控制台中,我看到两个 http 请求。一个给出 POST,GET,HEAD 的响应,XHR 显示​​为状态 200,另一个给出正确的响应,但 XHR 状态显示为其他。 http.Request 在服务中,订阅在组件 class 中。

服务 class 是

export class Httpprovider {
    http: Http;
    constructor(http: Http){
        this.http = http;
    }
    httpReq(url: string, method: string, data: any, header: Headers){
        let headers = new Headers();
        headers.append('Content-Type', 'application/json');
        console.log(headers);

        if (method === 'GET'){ var methods = RequestMethod.Get} 
        else if (method === 'POST'){ var methods = RequestMethod.Post}
        else if (method === 'PUT'){var methods = RequestMethod.Put}
        else if (method === 'PATCH'){var methods = RequestMethod.Patch} 
        else if (method === 'DELETE'){var methods = RequestMethod.Delete}
        else {methods = RequestMethod.Get};

        return this.http.request(new Request({
                    method: methods,
                    url: url,
                    body: JSON.stringify(data),
                    headers: headers
                })).map(res => res.json());
    }

}

要么您多次订阅 HttpProvider.httpRequ(...).subscribe(),要么是 CORS 预检调用(属于 OPTIONS AFAIR 类型),因此可能是前者。