我正在尝试在下面的Java程序中读取简单的json对象:
public class Hello{
@POST
@Path("/jsonRequest")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response getJson(String url) throws InterruptedException, IOException {
JSONObject json= readJsonFromUrl(url);
Response.ResponseBuilder response = Response.ok(json);
return response.build();
}
public static JSONObject readJsonFromUrl(String url) throws IOException, JSONException {
JSONObject json = new JSONObject(IOUtils.toString(new URL(url), Charset.forName("UTF-8")));
return json;
}
但是,当我尝试通过POSTMAN发出POST请求时,我收到以下错误:
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: java.net.MalformedURLException: no protocol:{"name":"pallavi",
"location":"Bangalore"}
有人可以帮我确定我哪里错了吗?任何帮助都非常感谢