繁体   English   中英

如何发送具有多个参数的发布请求

[英]How to send a post request with multiple parameters

我有一个项目,我们从Java Script调用GET方法:被调用的方法如下:

public
@ResponseBody
Map run( @RequestParam Map map, HttpServletRequest request,   HttpServletResponse response) throws Exception {

}

现在,我正在编写一个Micro服务来完成上述方法中完成的工作。 要求是该方法将调用微服务。我唯一遇到的是将(HttpServletRequest请求,HttpServletResponse响应)传递给我正在调用的微服务中的方法,因为它们中有一些数据用过的。

我在微服务中的方法定义如下:

@POST
@Path("/myPostCall")
public String myPostCall(Map map,HttpServletRequest request,       HttpServletResponse response) throws Exception{
}

现在,我试图通过

 RestTemplate abc = new RestTemplate();
abc.postForObject("http://localhost:8008/report/run", report1, String.class);

它给我422错误。 但是如果我删除请求,则使用微服务方法响应参数。 运行良好。 但是我也需要它们。 因为他们里面有数据。 我有什么不了解的东西吗?

您可以在类中将它们用作私有变量,例如:

@Context 
private HttpServletRequest request;
@Context 
private HttpServletResponse response;

要么

@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.

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