简体   繁体   English

拦截和修改请求体

[英]Intercept and modify request body

In a request body object that I expect in my POST endpoint there are three fields, let's say A, B, C. Users can pass: 1. Both A and B 2. Only C.在我期望在我的 POST 端点中的请求正文对象中有三个字段,假设 A、B、C。用户可以通过: 1. A 和 B 2. 只有 C。

In the second case (when only C is provided) I need to retrieve A and B from mapping in a database and add these to the request body to be validated later in my custom authorization filter.在第二种情况下(仅提供 C 时),我需要从数据库中的映射中检索 A 和 B,并将它们添加到请求正文中,以便稍后在我的自定义授权过滤器中进行验证。

I've tried two thins - creating another authorization filter and delegate handler.我尝试了两种方法 - 创建另一个授权过滤器和委托处理程序。 I managed to get the A and B from a database, but I don't know how to add them to the request body.我设法从数据库中获取 A 和 B,但我不知道如何将它们添加到请求正文中。 Also, once the request body stream was read it couldn't be used again in the validation function.此外,一旦请求正文流被读取,它就不能在验证函数中再次使用。

I'll go out on a limb and say that you shouldn't be looking to modify the incoming request.我会说你不应该修改传入的请求。 Instead change the code in your 'custom authorization filter' to retrieve fields A and B when only C is provided.而是更改“自定义授权过滤器”中的代码以在仅提供 C 时检索字段 A 和 B。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM