android 使用http协议上传文件

来源:互联网 发布:小猪cms智慧店铺源码 编辑:程序博客网 时间:2024/05/22 03:09

http://www.aslibra.com/blog/post/android-upload-files-to-server.php

补充:android平台调用post方法进行文件传输:

public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.main);        new Thread(new Runnable(){public void run() {String actionUrl = "http://202.201.12.19/uploadFile.php";        Map<String, String> strParams = new HashMap<String, String>();        strParams.put("paramOne", "valueOne");        strParams.put("paramTwo", "valueTwo");        Map<String, File> files = new HashMap<String, File>();        files.put("tempAndroid1.txt", new File("/mnt/sdcard/HelloWorld1.txt"));        try{        Log.i("xiao", "post Result = " + post(actionUrl, strParams, files));        }        catch(Exception e){        Log.i("xiao", "Exception = " + e.getMessage());        }}        }).run();    }

注意:我服务器端(linux)的代码和转载的博客写的一样,但总是不能进行传输,因为服务器端我没有对当前文件夹进行写入的权限,进入/var/www目录,加上chmod  777 .就可以了。


一个写的挺好的上传和下载博客:

http://www.cnblogs.com/fly_binbin/archive/2010/12/18/1910273.html

原创粉丝点击