HTTP multipart classes in java

I'm trying to follow the answer to THAT question

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);

I have the following errors:

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 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
链接地址: http://www.djcxy.com/p/45848.html

上一篇: 如何通过url.openStream()发送POST数据?

下一篇: java中的HTTP multipart类