【发布时间】: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