我正在使用RESTEasy堆栈来实现基于REST的客户端和服务器。我有一个处理POST
请求的服务,如下所示:
@POST
@Path("/this")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public String testPost(@QueryParam("thing") String thing) {
...
}
当我从Postman或REST客户端致电时,以下URI:
http://ip:port/base/this?thing={"id":"abc"}
我总是得到错误
java.net.URISyntaxException: Illegal character in query at index (pointing to =)
这是什么原因呢?
如果您尝试解析POST请求,则应使用@FormParam而不是@QueryParam。然后,您可以通过以下方式发出发布请求(使用curl)
curl -i -X POST -H "Content-Type: application/json" -d thing="{\"id\":\"abc\"}" http://ip:port/base/this
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句