0

我在使用多个 @pathparams 的 Jersey 数据库上发布文件时遇到问题(没有 @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 而无法正常工作。有人知道解决方案吗?

4

1 回答 1

0

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

于 2013-07-23T15:51:58.170 回答