zoukankan      html  css  js  c++  java
  • HttpGet,HttpPost,HttpPut,HttpDelete

    HttpGet-get and show data,the param will show in address url.(when the param is too long,use HttpPost is a wise choice.)

    HttpPost-save and update data,the param will be hided.

    HttpPut-add and create file/data on server

    HttpDelete-delete file/data on server

     

    HttpPut

    Public Constructors

    public HttpPut ()

    public HttpPut (URI uri)

    public HttpPut (String 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......

  • 相关阅读:
    基于Yarp的http内网穿透库HttpMouse
    Redis+Lua解决高并发场景抢购秒杀问题
    SQL慢查询排查思路
    webrtc之TURE、STUN、摄像头打开实战
    WebService就该这么学
    超详细 Java 15 新功能介绍
    Java 14 新功能介绍
    Java 17 将要发布,补一下 Java 13 中的新功能
    Java 8 Function 函数接口
    PO/DO/VO/DTO/BO/POJO概念与区别
  • 原文地址:https://www.cnblogs.com/qiengo/p/2508835.html
Copyright © 2011-2022 走看看