简体   繁体   English

如何将 HttpServletRequest 从一个 controller 传递给另一个

[英]How to pass HttpServletRequest from one controller to other

I have a problem statement where I need to pass HttpServletRequest from one controller to another so that I can extract the Authorization header in another controller.我有一个问题声明,我需要将 HttpServletRequest 从一个 controller 传递到另一个,以便我可以在另一个 controller 中提取授权 header。 Any lead appreciated please let me know how I can pass it through feign client API request and How I accept it in another controller.任何领导赞赏请让我知道如何通过假装客户端 API 请求传递它,以及如何在另一个 controller 中接受它。

Thanks in advance.提前致谢。

This is the simple example that how you will pass the Httprequest from one controller to other controller.这是一个简单的示例,说明如何将 Httprequest 从一个 controller 传递到另一个 controller。

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);

MultiValueMap<String, Object> form = new LinkedMultiValueMap<>();
form.add("name", request.getParameter("name"));
form.add("abc", request.getParameter("abc"));
form.add("xyz", request.getParameter("xyz"));

HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(form, httpHeaders);
restTemplate.postForEntity("http:localhost:8080/save", requestEntity, String.class);

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

相关问题 如何在Spring中将ModelMap从一个控制器传递到另一个 - How to pass ModelMap from one controller to other in Spring 传递HttpServletrequest属性以公开从控制器调用的方法是否可以? - Is it fine to pass HttpServletrequest attribute to expose to the methods that is called from the controller 从HttpServletRequest获取目标控制器 - Get destination controller from a HttpServletRequest 如何将对象从一个控制器传递到另一个控制器 - How to pass an object from one controller to another controller 如何在Spring MVC中将LIST从一个控制器传递到另一个控制器 - How to pass LIST from one controller to another controller in spring mvc 如何将用户对象从一个控制器传递到另一个JavaFX控制器? - How to pass the User object from one Controller to the different JavaFX Controller? 如何将HTTPRequest从一个控制器类重定向到另一控制器类? - How to redirect a HTTPRequest from one controller class to other controller class? 在Spring控制器中从HttpServletRequest读取对象 - Read Object from HttpServletRequest in Spring controller 如何将FXML ComboBox实例从一个控制器传递到另一个? - How to pass FXML ComboBox instance from one controller to another? SpringBoot:如何将数据从一个控制器传递到另一个控制器? - SpringBoot: How to pass data from one controller to another?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM