本文整理汇总了TypeScript中@angular/common/http.HttpRequest.clone方法的典型用法代码示例。如果您正苦于以下问题:TypeScript HttpRequest.clone方法的具体用法?TypeScript HttpRequest.clone怎么用?TypeScript HttpRequest.clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类@angular/common/http.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.clone方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: intercept
/**
* Intercept the http request.
*
* @param req
* @param next
*/
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
req = req.clone({
headers: this.http.headers,
url: this.http.getUrl(req.url)
});
return next.handle(req);
}
示例2: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
var token = localStorage.getItem('token'); //1
var newHeader: HttpHeaders = req.headers; //2
newHeader = newHeader.set('Content-Type', 'application/json'); //3
if(token) newHeader = newHeader.set('x-access-token', token); //4
const newReq = req.clone({headers: newHeader}); //5
return next.handle(newReq); //6
}
示例3: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
request = request.clone({
setHeaders: {
Authorization: `Bearer ${this.token}`
}
});
return next.handle(request);
}
示例4: intercept
intercept(req: HttpRequest<any>, next: HttpHandler):
Observable<HttpEvent<any>> {
console.log("interceptor: " + req.url);
req = req.clone({
withCredentials: true
});
return next.handle(req);
}
示例5: intercept
intercept(request: HttpRequest<any>, next: HttpHandler):
Observable<HttpEvent<any>> {
const url = environment.origin + request.url;
const updatedRequest = request.clone({
url: url
});
return next.handle(updatedRequest);
}
示例6: mergeMap
mergeMap((headersWithBearer) => {
const kcReq = req.clone({ headers: headersWithBearer });
return next.handle(kcReq)
.pipe(
catchError((error) => {
return observableThrowError(error);
})
);
})
示例7: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
request = request.clone({
setHeaders: {
Authorization: 'SharedKey aneesphotostore:'
}
});
return next.handle(request);
}
示例8: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
const JWT = `Bearer ${this.token}`;
req = req.clone({
setHeaders: {
Authorization: JWT
}
});
return next.handle(req);
}
示例9: intercept
intercept(request: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
// TODO: Get token from users service
const token = 'Bearer yXuIbM4Fdr7yE3AAQFEM21ckiyqEpARUgPSQO5dOqZjf587xyq2At8QzQVuC';
const updatedRequest = request.clone({
headers: request.headers.set('Authorization', token)
});
return next.handle(updatedRequest);
}
示例10: intercept
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
if(req.headers.get('Authorization') === null){
const authHeader = localStorage.getItem('token');
const authReq = req.clone({ headers: req.headers.set('Authorization', 'Bearer ' + authHeader) });
return next.handle(authReq);
} else {
return next.handle(req);
}
}