请帮忙看看这段代码上传文件为什么传不上去,出了什么问题,谢谢
package com.echo.upload.service;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
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.ByteArrayEntity;
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import android.content.Context;
import android.util.Log;
import android.widget.Toast;
public class Hpclt {
public static void uploadFile(Context context, String srcPath) {
String uploadUrl = "http://172.20.58.159:8086/upload_file_service/UploadServlet";
File file = new File(srcPath);
if (!file.exists()) {
Log.i("nofile", "file no exists");
return;
}
try {
FileEntity reqEntity = new FileEntity(file, "binary/octet-stream");
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(uploadUrl);
httppost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
InputStream is = resEntity.getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
StringBuffer buffer = new StringBuffer();
String str = null;
while ((str = br.readLine()) != null) {
buffer.append(str + "\n");
}
is.close();
Toast.makeText(context, buffer.toString(), Toast.LENGTH_LONG)
.show();
httpclient.getConnectionManager().shutdown();
} catch (Exception e) {
e.printStackTrace();
}
}
}