我用文件上傳圖片文件到網站。我收到了錯誤消息。你能給我一些建議嗎?感謝 操作系統:Android 4.0.3 phone:htc x
http沒有迴應
error information
E/dalvikvm(11952): Could not find class 'org.apache.http.entity.mime.content.FileBody', referenced from method tw.tcc.tsvs.www.FileUploadPost.FileUploadPostActivity$1.onClick
代碼
import java.io.BufferedReader;
import java.io.File;
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.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.mime.HttpMultipartMode;
import org.apache.http.entity.mime.MultipartEntity;
import org.apache.http.entity.mime.content.FileBody;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
private Button.OnClickListener jclove=new OnClickListener(){
public void onClick(View v) {
try {
//file_post
File file = new File("/sdcard/android.jpg");
try {
HttpClient client = new DefaultHttpClient();
String postURL = "http://latest.tsd2497r1.ext.hipaas.hinet.net/";
HttpPost post = new HttpPost(postURL);
FileBody bin = new FileBody(file);
MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);
reqEntity.addPart("myFile", bin);
post.setEntity(reqEntity);
HttpResponse response = client.execute(post);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
//}
} catch (Exception e) {
e.printStackTrace();
}
}
};
看到這個討論https://groups.google.com/forum/?fromgroups#!topic/android-developers/QQSWZ_sWdgU – 2012-07-25 09:58:44
非常感謝。我會嘗試。 – user1430445 2012-07-25 10:46:54
工作! ...感謝imrankhan – user1430445 2012-07-26 05:26:33