安卓實訓第四天--基於HttpClient來完成資料在伺服器和裝置間的互動。

來源:互聯網
上載者:User

標籤:style   class   c   code   http   a   

上午:老師首先回顧了昨天作業。
首先在安卓工程中的TOOLS檔案中,解析位元組流那裡,不用改變,而是把伺服器端的編碼方式變為UTF-8,然後將在安卓工程的LoginActivity類中的USERNAME給他強制轉換下。
總結一句話:如果一個字元通過某個編碼轉換成位元組碼之後,那你在轉換的時候必須拿到轉換之前的位元組碼補充:如何改變mysql串連工具的編碼方式:jdbc:mysql://localhost:3306/databasename?useUnicode=true&characterEncoding=UTF-8 問號後面加上那個就行了
如果是hibernate的話配置到<property name="connection.url">裡面
mysql不支援中文,不過取出來的時候是可以還原成中文的.
然後講了比HttpUrlConnection更簡單快捷的方法來完成對伺服器的互動。
一個方法new的誰,就執行誰的方法,如果在方法中使用了SUPER關鍵字調用其父親的方法,那麼就先執行父親,如果父親的方法也使用了SUPER,那麼一次先執行,父親的父親的方法
  然後注意一個網站GitHub,以下是從這個網站上面翻譯過來的HttpClient相關內容: Features
  • Make asynchronous HTTP requests, handle responses in anonymous callbacks
  • HTTP requests happen outside the UI thread
  • Requests use a threadpool to cap concurrent resource usage
  • GET/POST params builder (RequestParams)
  • Multipart file uploads with no additional third party libraries
  • Tiny size overhead to your application, only 25kb for everything
  • Automatic smart request retries optimized for spotty mobile connections
  • Automatic gzip response decoding support for super-fast requests
  • Binary file (images etc) downloading with BinaryHttpResponseHandler
  • Built-in response parsing into JSON with JsonHttpResponseHandler
  • Persistent cookie store, saves cookies into your app’s SharedPreferences
特性
進行非同步HTTP請求,處理響應在匿名回調
HTTP請求發生在UI線程
請求使用threadpool帽並發資源使用方式
GET / POST參數構建器(RequestParams)
多部分檔案上傳,沒有額外的第三方庫
小尺寸應用程式開銷,只有25 kb為我所做的一切
自動智能移動串連請求重試最佳化參差不齊
自動解碼支援gzip反應速度超快的請求
二進位檔案(圖片等)與BinaryHttpResponseHandler下載
內建的解析與JsonHttpResponseHandler JSON響應
持久化cookie儲存、儲存cookie到你的應用程式的SharedPreferences   

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.