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;
}
精彩评论