开发者

upload file using http put -T in android?

I have an android class which use http put to call REST web service . But it create empty folder no content how do i do? when i test开发者_JAVA百科 web service using curl command it works and can upload successfully.

curl -v -T C:\downloads\a.jpg -H "Content-Type:application/vnd.org.snia.cdmi.dataobject" http://192.168.37.241:8080/kyaw/ktest/a.jpg

public class putandroid extends Activity {

    public void onCreate(Bundle savedInstanceState)
    {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    TextView txt = (TextView) findViewById(R.id.textView1);
    txt.setText(getInputStreamFromUrl("http://192.168.37.241:8080/kyaw/ktest/a.jpg"));
    }

    public static String getInputStreamFromUrl(String url) {
          String content = null;
          HttpResponse response = null;
          try {

DefaultHttpClient httpclient = new DefaultHttpClient();             
            HttpPut put=new HttpPut(url);
            File f=new File("C:\\downloads\\a.jpg");
            FileEntity reqEntity=new FileEntity(f,"images/jpg");
            put.setEntity(reqEntity);
            put.setHeader("Content-Type","application/vnd.org.snia.cdmi.dataobject");
            response = httpclient.execute(put);
            HttpEntity resEntity=response.getEntity();
            if(resEntity!=null)
            content = (EntityUtils.toString(resEntity));
          }catch (Exception e) {
            Log.e("PUT Exception", "java.lang.NullPointerException");
          }
            String result=response.getStatusLine().toString()+"\n"+content;

            return result;
        }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜