[英]How to send a post request with multiple parameters
I have a project where we call a GET method from Java Script : the method called is below : 我有一个项目,我们从Java Script调用GET方法:被调用的方法如下:
public
@ResponseBody
Map run( @RequestParam Map map, HttpServletRequest request, HttpServletResponse response) throws Exception {
}
Now I am writing a Micro service to do the work which is done inside the above method . 现在,我正在编写一个Micro服务来完成上述方法中完成的工作。 And the requirement is this method will call the micro-service .The only thing I am stuck with is passing the (HttpServletRequest request, HttpServletResponse response) to the method in micro-service I am calling as they have some data in there which will be used.
要求是该方法将调用微服务。我唯一遇到的是将(HttpServletRequest请求,HttpServletResponse响应)传递给我正在调用的微服务中的方法,因为它们中有一些数据用过的。
My method definition in micro-service looks like : 我在微服务中的方法定义如下:
@POST
@Path("/myPostCall")
public String myPostCall(Map map,HttpServletRequest request, HttpServletResponse response) throws Exception{
}
Now I am trying to call this by 现在,我试图通过
RestTemplate abc = new RestTemplate();
abc.postForObject("http://localhost:8008/report/run", report1, String.class);
It gives me 422 error . 它给我422错误。 But If I remove the request,response parameters in micro-service method .
但是如果我删除请求,则使用微服务方法响应参数。 it runs good .
运行良好。 But I need them too .
但是我也需要它们。 Because they have data in it .
因为他们里面有数据。 Is there something out of my understanding .
我有什么不了解的东西吗?
You can use them as private variables in class as : 您可以在类中将它们用作私有变量,例如:
@Context
private HttpServletRequest request;
@Context
private HttpServletResponse response;
OR 要么
@POST
@Path("/myPostCall")
public String myPostCall(..., @Context HttpServletRequest request, @Context HttpServletResponse response) throws Exception{
//do some stuff
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.