使用 HttpClient 触发点击发布请求的两个调用 [英] Two calls triggering on click of post request using HttpClient
问题描述
在代码中添加标头后,重复调用正在发生.找到图片以查看通话发生了两次.
auth-interceptor.ts
导出类 AuthInterceptor 实现 HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>>{const clonedRequest = req.clone({标头:req.headers.set('X-CustomAuthHeader', 'some-auth-token')});console.log("新标头", clonedRequest.headers.keys());返回下一个.句柄(克隆请求);}
}
参考这里.
After adding headers inside code duplicate call is happening. find the image to see the call happening twice.
auth-interceptor.ts
export class AuthInterceptor implements HttpInterceptor {
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const clonedRequest = req.clone({
headers: req.headers.set('X-CustomAuthHeader', 'some-auth-token')
});
console.log("new headers", clonedRequest.headers.keys());
return next.handle(clonedRequest);
}
}
Please fine calls log image here..
This type of request is called Preflighted requests that corresponds to a negotiation between the caller and the Web application based on HTTP headers.
It consists of two phases:
The browser executes an OPTIONS request with the same URL as the target request to check that it has the rights to execute the request. This OPTIONS request returns headers that identify what is possible to do for the URL.
If rights match, the browser executes the request.
这篇关于使用 HttpClient 触发点击发布请求的两个调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!