jquery - 如何从 Header 中检索表单数据信息
问题描述
我有从付款页面返回的 angular2+ 页面,其中包含表单数据标题中的状态信息如何在 angular2 中检索此信息
在 asp.net 中很容易通过 Request.form["Key"] 获得,如何在 angular/Jquery 应用程序中实现相同的事情
以下是上车信息
解决方案
这可以使用 HttpInterceptor 来完成(如果您需要修改和记录请求)
@Injectable()
export class MyHttpInterceptor implements HttpInterceptor {
constructor() {}
intercept(req: HttpRequest < any > , next: HttpHandler): Observable < HttpEvent < any >> {
console.log("intercepted request ... ");
// Clone the request to add the new header.
const authReq = req.clone({
headers: req.headers.set("headerName", "headerValue")
});
console.log("Sending request with new header now ...");
//send the newly created request
return next.handle(authReq)
.catch((error, caught) => {
//intercept the respons error and displace it to the console
console.log("Error Occurred");
console.log(error);
//return the error to the method that called it
return Observable.throw(error);
}) as any;
}
}
推荐阅读
- git - 在等待审阅者合并拉取请求时,我应该从分支分支吗?
- javascript - 试图调用 2 个 JS 文件,但只有 1 个有效
- javascript - 如何在反应js javascript中映射这个给定的api响应
- r - 二进制运算符错误的Sjplot非数字参数?
- sql - 查找数据集中每年可用的每个国家/地区的前 2 个供应商?- 大查询 SQL
- android - vivo杀死应用程序时不接收广播
- kubernetes - Tekton 仪表板部署错误-来自服务器的错误(禁止):创建“config/service.yaml”时出错
- android - Flutter 使用 Cloud Firestore 和 Firebase Auth 存储用户数据
- visual-studio-code - 如何在 VS Code 1.57 中禁用工作区信任?
- r - 如何使用 lapply 遍历 ggplot2 中的 2 个变量