【问题标题】:RESTful Android client with @pathparm server based on Jersey带有基于 Jersey 的 @pathparm 服务器的 RESTful Android 客户端
【发布时间】:2013-07-23 13:37:39
【问题描述】:

我无法在 Jersey 数据库上发布具有多个 @pathparams 的文件(没有 @pathparam 测试,有效!!)。

服务器代码为:

@POST
@Path("visit_add_image/{key}/{idvisita}/{body}/{img}/{img2}")
@Produces(MediaType.TEXT_XML)
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String visit_add_image(  @FormDataParam("key")String key, 
                                @FormDataParam("idvisita")Integer idvisita,
                                @FormDataParam("body")String body,
                                @FormDataParam("img")InputStream img,
                                @FormDataParam("img")FormDataContentDisposition imgDetail,
                                @FormDataParam("img2")InputStream img2,
                                @FormDataParam("img2")FormDataContentDisposition imgDetail2) throws SQLException{
    return "";
}

而客户端是这样的:

HttpClient httpclient = new DefaultHttpClient();
        HttpPost httppost = new HttpPost(url../user/visit_add_image/11/111/112");


        FileBody fileContent= new FileBody(new File("/Users/Achron/Downloads/sun.jpg"));
        FileBody fileContent2 = new FileBody(new File("/Users/Achron/Downloads/sun.jpg"));
        MultipartEntity reqEntity = new MultipartEntity();

        reqEntity.addPart("img", fileContent);
        reqEntity.addPart("img2", fileContent2);
        httppost.setEntity(reqEntity);
        HttpResponse response = null;
        try {
            response = httpclient.execute(httppost);
            System.out.println("file "+response.toString()+""+" e stato inviato al server");
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

因为服务器的答案是 404 而无法正常工作。有人知道解决方案吗?

【问题讨论】:

    标签: java android client jersey restful-url


    【解决方案1】:

    您发布到的 URL 与资源上的 @Path 不同,这就是您收到 404 的原因。确保您的 HttpPost 请求中包含正确数量的路径元素。

    【讨论】:

      猜你喜欢
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-15
      相关资源
      最近更新 更多