2

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.

Community
  • 1
  • 1
Addev
  • 31,819
  • 51
  • 183
  • 302

1 Answers1

6

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
Perception
  • 79,279
  • 19
  • 185
  • 195