HttpGet,HttpPost,HttpPut,HttpDelete
HttpPut
Public Constructors
public HttpPut ()
public HttpPut (URI uri)
can be used to upload file,for example:
private void uploadFile(String fileName,String urlFolder){ Log.i(LOG_TAG, "uploadFile:"+urlFolder+fileName); try { HttpClient client = new DefaultHttpClient(); HttpPut put= new HttpPut(urlFolder+fileName); File record=new File(LogFile); if(record.exists()){ FileEntity fileEntity=new FileEntity(record,"UTF-8" ); put.setEntity(fileEntity); HttpResponse response = client.execute(put); Log.i(LOG_TAG, "response:"+response.getStatusLine()); if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK ||response.getStatusLine().getStatusCode() == HttpStatus.SC_CREATED){ Log.i(LOG_TAG, "Upload OK!"); SharedPreferences settings = mContext.getSharedPreferences(Preferences.NAME_PREFERENCES, 0); SharedPreferences.Editor editor = settings.edit(); editor.putLong(LAST_UPLOADTIME, System.currentTimeMillis()); editor.commit(); } }else{ Log.i(LOG_TAG, "record file not exsit!"); } } catch (Exception e) { e.printStackTrace(); } }
About this method,I just want to uplaod text file,so if you want to deal with the media.You have to study it by youself.
ing......