首页 > 解决方案 > 如何从 Header 中检索表单数据信息

问题描述

我有从付款页面返回的 angular2+ 页面,其中包含表单数据标题中的状态信息如何在 angular2 中检索此信息

在 asp.net 中很容易通过 Request.form["Key"] 获得,如何在 angular/Jquery 应用程序中实现相同的事情

以下是上车信息

Header的formdata信息

在此处输入图像描述

标签: jqueryangular

解决方案


这可以使用 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;
    }
}

更多信息在这里这里


推荐阅读