java中的HTTP多部分类



我正试图找到这个问题的答案

但类似乎不包括在默认的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);

我有以下错误:

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

我该如何解决这些错误,是否有一些库必须添加?如果是,请告诉我如何下载。

HttpClient(现在)是一个接口。请改用DefaultHttpClient。以下是您列出的其他一些替换类:

FilePart-FileBodyMultipartRequestEntity-MultipartEntity部分-ContentBodyPostMethod-HttpPost

最新更新