Tag: androidhttpclient

Android:下载文件并保存在SD卡上

试图创建一个应用程序来下载SD卡上的文件,这是我的代码: public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); new Thread(new Runnable() { public void run() { Log.i(“step0″,”it starts here”); URLConnection urlConnection = null; // TODO Auto-generated method stub try { //fetching the URL Log.i(“step 1.1″,”getting the url”); URL url = new URL(“http://people.opera.com/howcome/2005/ala/sample.pdf”); Log.i(“step 1.2″,”captured the url”); urlConnection = […]

在Android中进行多部分文件上传的好方法

我正在处理一段代码来执行多部分表单数据POST请求,在我的情况下,这只是将图像上传到带有参数的服务器。 这就是我现在拥有的: 我有一个触发多部分请求的按钮,在按钮OnClickListener中,我有这个代码来旋转一个新线程: new Thread(new Runnable(){ @Override public void run() { String photoUri = getPhotoUri(); String url = getEndPointUrl(); try { NewPostRequest.postFile(url, photoUri, ); } catch (Exception e) { // Exception Handling } }).start(); 而NewPostRequest.postFile只是使用Apache Http Client发出请求,基本如下: HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); MultipartEntityBuilder builder = MultipartEntityBuilder.create(); builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); File file = […]