java中的HTTP多部分类

Add*_*dev 2 java http

我试图按照答案THAT问题

但是,对于该代码,似乎默认的Android包中不包含类:

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);
Run Code Online (Sandbox Code Playgroud)

我有以下错误:

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
Run Code Online (Sandbox Code Playgroud)

如何解决这些错误,我必须添加一些库吗?如果是,请让我知道如何下载它.

Per*_*ion 6

HttpClient是(现在)一个界面.请DefaultHttpClient改用.这是您列出的其他一些替换课程:

FilePart - FileBody
MultipartRequestEntity - MultipartEntity
Part - ContentBody
PostMethod - HttpPost