我正在尝试以JSON格式向Rest服务发送请求。当我发送请求时:
http://localhost:8080/MyProject/MyPackage/hello/{"no":"12","op":"read"}
它工作正常,但是当我尝试发送数组以及其他参数时:
http://localhost:8080/MyProject/MyPackage/hello/{"no":"12","op":"read","attributes":[{"name"},{"id"}]}
这里我得到的错误是:
<html><head><title>Apache Tomcat/7.0.32 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 500 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Exception report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The server encountered an internal error that prevented it from fulfilling this request.</u></p><p><b>exception</b> <pre>java.lang.IllegalArgumentException
java.net.URI.create(URI.java:841)
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:95)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
</pre></p><p><b>root cause</b> <pre>java.net.URISyntaxException: Illegal character in path at index 143: http://localhost:8080/social_soa/social_soa/hello/%7B%22hashkey%22:%2212%22,%22operation%22:%22read%22%20,%22count%22:%222%22,%22attributes%22:[%7B%22name%22%7D]%7D
java.net.URI$Parser.fail(URI.java:2810)
java.net.URI$Parser.checkChars(URI.java:2983)
java.net.URI$Parser.parseHierarchical(URI.java:3067)
java.net.URI$Parser.parse(URI.java:3015)
java.net.URI.<init>(URI.java:577)
java.net.URI.create(URI.java:839)
javax.ws.rs.core.UriBuilder.fromUri(UriBuilder.java:95)
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:662)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
</pre></p><p><b>note</b> <u>The full stack trace of the root cause is available in the Apache Tomcat/7.0.32 logs.
休息服务类就像这样
public class RestService {
private static final Logger LOGGER = Logger.getLogger(RestService.class.getName());
@GET
@Path("/{param}")
@Consumes("text/plain")
@Produces("application/json")
public String readJSON(@PathParam("param") String json) {
//doing mytask
}
在第一种情况下,上述功能的主体是可访问的,但在2种情况下它甚至没有进入功能体。
这个错误的根本原因是什么?