//定義HttpClient對象
HttpClient client = new DefaultHttpClient();
//獲得HttpPost對象
HttpPost post = new HttpPost("http://192.168.1.106:8001/2012/upload.php");
post.addHeader("charset", HTTP.UTF_8);
//實例化
MultipartEntity me = new MultipartEntity();
try {
me.addPart("content",new StringBody("12cccafasdfasdf"));
me.addPart("title",new StringBody("csdnliwei"));
me.addPart("local",new StringBody("beijing"));
//設置流文件
me.addPart("file", new InputStreamBody(new FileInputStream("/mnt/sdcard/test.jpg"), "image/pjpeg", "fengjie.jpg"));
post.setEntity(me);
//獲得響應消息
HttpResponse resp = client.execute(post);
if(resp.getStatusLine().getStatusCode()==200){
Toast.makeText(this, "文件上傳文成!", 1).show();
}
} catch (Exception e) {
e.printStackTrace();
}
}