java中的HTTP多部分类 [英] HTTP multipart classes in java
本文介绍了java中的HTTP多部分类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试按照那个问题的答案
I'm trying to follow the answer to THAT question
但似乎默认的Android软件包中没有包含类,因为该代码:
But it seems that classes are not included with the default Android package since for that code:
File file = new File("FileToSend.txt");
HttpClient client = new HttpClient();
String url = "http://www.yourdomain.com/destination.php";
PostMethod postMethod = new PostMethod(url);
Part[] parts = {new FilePart(file.getName(), file)};
postMethod.setParameter("name", "value"); // set parameters like this instead in separate call
postMethod.setRequestEntity( new MultipartRequestEntity(parts, postMethod.getParams()));
int status = client.executeMethod(postMethod);
我有以下错误:
Cannot instantiate the type HttpClient
FilePart cannot be resolved to a type XXXXX.java
MultipartRequestEntity cannot be resolved to a type XXXXX.java
Part cannot be resolved to a type XXXXX.java
PostMethod cannot be resolved to a type XXXXX.java
如何我可以解决这些错误,我必须添加一些库吗?如果是,请让我知道如何下载它。
How can I solve those errors, is there some library I must add? if yes please let me know how can I download it.
推荐答案
HttpClient
(现在)是一个界面。请改用 DefaultHttpClient
。这是您列出的其他一些替代课程:
HttpClient
is (now) an interface. Use DefaultHttpClient
instead. Here's replacement classes for some of the others you listed:
FilePart - FileBody
MultipartRequestEntity - MultipartEntity
Part - ContentBody
PostMethod - HttpPost
这篇关于java中的HTTP多部分类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文