例外:java.net.MalformedURLException:通过POSTMAN读取json时没有协议

时间:2018-02-19 07:41:12

标签: java json post postman

我正在尝试在下面的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"}

POSTMAN请求如下:enter image description here

有人可以帮我确定我哪里错了吗?任何帮助都非常感谢

0 个答案:

没有答案