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 - FileBody MultipartRequestEntity - MultipartEntity 部分 - ContentBody PostMethod - HttpPost