java—如何将rest客户机写入使用jsonobject的服务?

mzillmmw  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(281)

我创建了一个使用jsonobject的webservice,如下所示:

@POST
    @Consumes({MediaType.APPLICATION_JSON})
    @Produces(MediaType.APPLICATION_OCTET_STREAM)
    @Path("/postjson")
    public Response postFile(JSONObject fichier) throws Exception{

        System.out.println("Filename = "+fichier.get("file"));

        return download( fichier.get("file").toString());
    }

当我开始执行客户端时,我得到了500个错误代码

JSONObject document=new JSONObject();
      document.put("file", "bbg.pdf");

      javax.ws.rs.client.Client client = ClientBuilder.newClient();
      WebTarget webTarget = client.target("http://localhost:7001/WSTest/webresources/files/")
              .path("postjson");
      Response response=webTarget.request()
                                 .post(Entity.json(document));
      System.out.println(response.getStatus());

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题