0

I have read plenty of explanations about how to upload files to a server through XML using C#, but I have not found how to do the same using Java and have not been able to figure it out at all. I wonder if anybody on you have done this job successfully.

My intention is to do an HTTP posts containing some text values as a caption and description of an image file, then post them and the image file to the web server through XML.

4

1 回答 1

0

使用 Jersey 上传文件非常容易。实际上,它可以让您以InputStream的形式访问文件内容。请参阅下面的示例代码:

@Consumes("multipart/form-data") 
@POST 
public void post(@FormParam("file") InputStream file) { 
  ... 
} 

对于客户端,Jersey 还可以帮助您发送 HTTP 请求。可以在这里找到一个很好的示例:http ://www.tuple23.com/2010/03/file-upload-using-jersey-client.html

于 2012-05-09T00:47:16.527 回答