小编Mat*_*Mat的帖子

找不到类'org.apache.http.entity.mime.content.Filebody',从方法中引用

我要做的是将图片发送到Web服务器.当我在Android项目中调用方法时,我收到以下错误:找不到类'org.apache.http.entity.mime.content.Filebody',从方法com.example.tc.Send.send引用.

虽然我有以下导入,但是会发生这种情况:

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
Run Code Online (Sandbox Code Playgroud)

这就是该方法所在的类:

public class Send {
public Send(){
}

public static String send(String path) throws Exception {
    String filePath = path;
    String svar;

    HttpClient httpclient = new DefaultHttpClient();
    try {
        HttpPost httppost = new HttpPost("path to web server"); 
        FileBody pic = new FileBody(new File(filePath)); 
        MultipartEntity requestEntity = new MultipartEntity(); 
        requestEntity.addPart("file", pic);

        httppost.setEntity(requestEntity);
        System.out.println("executing request " + httppost.getRequestLine());
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity responseEntity = response.getEntity(); …
Run Code Online (Sandbox Code Playgroud)

java error-handling android jar

9
推荐指数
2
解决办法
1万
查看次数

标签 统计

android ×1

error-handling ×1

jar ×1

java ×1