1. 程式人生 > >volley 之get、put、post、delete

volley 之get、put、post、delete

Google released Android Volley Library around May/June 2013, which has been internally used by Google for some time. It is supposed to provide Fast Networking Operations and also takes care of Threads nicely. If you are unfamiliar with Volley, please see Google I/O 2013 Video

Unfortunately, there is almost no documentation on Volley. So, I put together code snippets on how to make Volley HTTP Requests (GET, POST, PUT, DELETE).


Setting up Android Volley Library

Setting up is straight-forward. Clone the Volley project from here and then import the Volley into project. A comprehensive tutorial on setting up can be found here.


Key Classes of Android Volley

The following are the Key classes of Volley:

  • - RequestQueue: A Queue containing the Network/HTTP Requests that needs to be made.
  • - Request: A Base Class which contains Network related information like HTTP Methods.
  • - StringRequest: HTTP Request where the response is parsed a String. View Source
  • - JsonObjectRequest: HTTP Request where the response is JSONObject. View Source

Getting Started with Android Volley

At first make a RequestQueue, which holds the HTTP Requests. 

View Source. Ideally, the RequestQueue should be made once and then referred to it across the Application. The Application is an ideal place to make it.

?
1 RequestQueue queue = Volley.newRequestQueue(this);  // this = context

Making GET Requests

Making GET Requests is simple. The example below uses JsonObjectRequest. It prepares a JsonObjectRequest and passes and then adds it to RequestQueue. The JsonObject accepts 4 parameters (Http methodUrlJson valuesResponse Listener - Invoked on success, Error Listener - Invoked on failure).

?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 // prepare the Request JsonObjectRequest getRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() { @Override public void onResponse(JSONObject response) {   // display response     Log.d("Response", response.toString()); } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError error) {            Log.d(

相關推薦

volley getputpostdelete

Google released Android Volley Library around May/June 2013, which has been internally used by Google for some time. It is supposed to provide Fast N

HashMap原始碼getput方法

HashMap是基於陣列和連結串列來儲存鍵值對物件的,我們簡單看下get和put方法的原始碼。 1、我們呼叫put方法來儲存鍵值對時,它先呼叫hash方法來計算hashcode,然後用hashcode和Entry陣列的大小來做按位與操作,求出所在的Entry陣列的下標位置。通過key與下標所

認識和使用工具使用Postman模擬傳送getpostdeleteput請求

使用Postman模擬傳送get、post、delete、put請求 現在的模擬傳送請求外掛很多,包括在idea上都自帶了Test restful web service來模擬請求,但親測postman更好用一些 今天來分享如何使用postman傳送各種請求 1.下載 postman

Android Volley解析(一)GETPOST請求篇

一、 Volley 的地位 自2013年Google I/O 大會上,Google 推出 Volley 之後,一直到至今,由於其使用簡單、程式碼輕量、通訊速度快、併發量大等特點,倍受開發者們的青睞。 先看兩張圖,讓圖片告訴我們 Volley 的用處; 第一

Java程式設計HTTP的PostGetPutDelete

Http:在網路中,傳送檔案、資料需要遵循的一種協議。客戶端需要和伺服器端建立聯絡,就需要使用HTTP協議,保證伺服器端可以識別客戶端的請求,並把相應的資源發給客戶端使用。例如,訪問CSDN,在不同電腦的網頁上輸入https://www.csdn.net/即可看到CSDN的網

VolleyGetPost方式(JsonObjectRequestStringRequest)以及Volley獲取圖片的3種方式

volley use utf-8 設置 ica static toast 隊列 getheight activity_main.xml 裏面什麽也沒有 AndroidManifest.xml(重點是android:name="com.example.vo

Postman接口測試POSTGET請求方法

進行 edit 包含 刪除 登錄 功能 AD dev 代理服務 一、基礎知識   1.HTTP的五種請求方法:GET, POST ,HEAD,OPTIONS, PUT, DELETE, TRACE 和 CONNECT 方法。     GET請求:請求指定的頁面信息,並返回實

Node.js + Express 介面請求(GETPOSTPUT)事例

路由 路由是指應用程式的端點(URI)如何響應客戶端請求。有關路由的介紹,請參閱基本路由。 您可以使用Express app物件的方法定義路由,這些方法對應於HTTP方法; 例如,app.get()處理GET請求和app.post處理POST請求。有關完整列表,請參閱app.

Restful的GETPOSTPUTDELETEDPATCH幾種操作

HTTP Method 與 CURD 資料處理操作對應 HTTP方法 資料處理 說明 POST Create 新增一個沒有id的資源 GET Read

Postman介面測試POSTGET請求方法

一、基礎知識   1.HTTP的五種請求方法:GET, POST ,HEAD,OPTIONS, PUT, DELETE, TRACE 和 CONNECT 方法。     GET請求:請求指定的頁面資訊,並返回實體主體。(通常用來接收資料)。     POST請求:向指定資源提交資

getputpostdelete含義與區別

get、put、post、delete含義與區別 1、GET請求會向資料庫發索取資料的請求,從而來獲取資訊,該請求就像資料庫的select操作一樣,只是用來查詢一下資料,不會修改、增加資料,不會影響資源的內容,即該請求不會產生副作用。無論進行多少次操作,結果都是一樣的。 2、與GET不同的是,PUT請求是

LR腳本示例URL請求(postget

code start count last item sta val content orm Action(){ //application/x-www-form-urlencoded //application/json //web_add_auto_header("Co

LR指令碼示例URL請求(postget

Action(){ //application/x-www-form-urlencoded //application/json //web_add_auto_header("Content-Type","application/x-www-form-urlencoded");設定請求頭資訊 //1、停頓2

HTTP協議中POSTGETHEADPUT等請求方法以及一些常見錯誤

HTTP請求方法: 常用方法: Get\Post\Head (1)Get方法. 取回請求URL標誌的任何資訊,在瀏覽器的位址列中輸入網址的方式訪問網頁時,瀏覽器採用GET方法向伺服器獲取資源。 (2)Post方法.為請求報文準備資料,即要求被請求伺服器接受附在請求訊息

Android的Okhttp框架postget用法講解(落雨敏)

         前言:okhttp作為Android主流網路框架之一,但在近日okhttp網路請求卻比較火,主要原因是在谷歌官方在6.0以後在Android sdk已經移除了httpClient,加入我們okHttp。在常用的框架之中( vol

淺談http協議六種請求方法,getheadputdeletepostoptions區別

原帖:https://www.cnblogs.com/wei-hj/p/7859707.html 標準Http協議支援六種請求方法,即: 1、GET 2、POST 3、PUT 4、Delete 5、HEAD 6、Options 但其實我們大部分情況下只用到了GET和P

getpostputdelete區別與含義

最近讀了http的入門書籍《圖解HTTP》,雖然仍然是一知半解,但是總得寫點東西加深一下印象。 語義 http協議是基於tcp協議的應用層協議,tcp協議作為可靠的傳輸層協議,因此http協議也是可靠的。 日常開發過程中,最常用的是get post put delete,

GETPOSTPUTDELETE

方法 GET 向伺服器發資料請求獲資訊。同資料庫select,查資料但不改、增資料,不影響資源內容,無論多少次操作,結果相同。 PUT 向伺服器發資料改資訊。同資料庫update,改資料內容但不增資料

WebApi 4大方法getpostputdelete返回協議

GET - 向特定的資源發出請求。注意:GET方法不應當被用於產生"副作用"的操作中,例如在web app.中。其中一個原因是GET可能會被網路蜘蛛等隨意訪問。 POST - 向指定資源提交資料進行處理請求(例如提交表單或者上傳檔案)。資料被包含在請求體中。POST請求可能

WebApi 4大方法初探 getpostputdelete

1.新建一個webapi專案 2.新建一個 "webapi 控制器類" 3. 修改 Web API 路由     routeTemplate: "api/{controller}/{id}" 修改為: routeTemplate: "api/{controller}/{ac