java中的HTTP multipart类
我试图按照这个问题的答案
但是,由于该代码,似乎这些类不包含在默认的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 Part - ContentBody PostMethod - HttpPost链接地址: http://www.djcxy.com/p/45847.html