[Flutter]Dio

更新於 發佈於 閱讀時間約 1 分鐘

Dio是一個Dart Http請求庫,支援Restful API、FormData、攔截器、請求取消、Cookie管理、檔案上傳/下載、逾時等。

加入

dependencies:
dio: ^x.x.x #请使用pub上的最新版本



使用

GET

Response response;
response = await dio.get("/xxx");


POST

Response response;
response = await dio.post("/xxx",data:{"id":1,"name":"Tom"});


同時發送多個請求

Response response;
response = await Future.wait([dio.post("/xxx"),dio.get("/yyy")]);


Download

Response response;
response = await dio.download("https://www.google.com/",_savePath);


FormData

FormData formData = FormData.from({
"name": "Tom",
"age": 20,
});
Response response;
response = await dio.post("/info", data: formData);
留言
avatar-img
留言分享你的想法!
avatar-img
小黑與程式的邂逅
8會員
123內容數
嗨,我是一名程式設計師,會在這分享開發與學習紀錄。
2023/12/28
解析成List List items=json.decode(jsonStr); print(items[0]["your_key"]); 解析成Map Map<String, dynamic> user = json.decode(json); print('${user['your_k
Thumbnail
2023/12/28
解析成List List items=json.decode(jsonStr); print(items[0]["your_key"]); 解析成Map Map<String, dynamic> user = json.decode(json); print('${user['your_k
Thumbnail
2023/12/26
這邊會使用WebSocketChannel去與http://www.websocket.org做連線。 連線 final channel = IOWebSocketChannel.connect('wss://echo.websocket.events'); 接收 StreamBui
Thumbnail
2023/12/26
這邊會使用WebSocketChannel去與http://www.websocket.org做連線。 連線 final channel = IOWebSocketChannel.connect('wss://echo.websocket.events'); 接收 StreamBui
Thumbnail
2023/12/25
配置 idleTimeout:在httpClient請求結束後,會繼續保持連線,直到超過idleTimeout值才會關閉連接。 connectionTimeout:和伺服器建立連線逾時,如果超過connectionTimeout值則會拋出SocketException異常。 maxConnec
Thumbnail
2023/12/25
配置 idleTimeout:在httpClient請求結束後,會繼續保持連線,直到超過idleTimeout值才會關閉連接。 connectionTimeout:和伺服器建立連線逾時,如果超過connectionTimeout值則會拋出SocketException異常。 maxConnec
Thumbnail
看更多
你可能也想看
Thumbnail
「欸!這是在哪裡買的?求連結 🥺」 誰叫你太有品味,一發就讓大家跟著剁手手? 讓你回購再回購的生活好物,是時候該介紹出場了吧! 「開箱你的美好生活」現正召喚各路好物的開箱使者 🤩
Thumbnail
「欸!這是在哪裡買的?求連結 🥺」 誰叫你太有品味,一發就讓大家跟著剁手手? 讓你回購再回購的生活好物,是時候該介紹出場了吧! 「開箱你的美好生活」現正召喚各路好物的開箱使者 🤩
Thumbnail
Request內容 package main import ( "fmt" "log" "net/http" "strings" ) func request(w http.ResponseWriter, r *http.Request) { //這些資訊是輸出到伺服器端的列印訊息
Thumbnail
Request內容 package main import ( "fmt" "log" "net/http" "strings" ) func request(w http.ResponseWriter, r *http.Request) { //這些資訊是輸出到伺服器端的列印訊息
Thumbnail
配置 idleTimeout:在httpClient請求結束後,會繼續保持連線,直到超過idleTimeout值才會關閉連接。 connectionTimeout:和伺服器建立連線逾時,如果超過connectionTimeout值則會拋出SocketException異常。 maxConnec
Thumbnail
配置 idleTimeout:在httpClient請求結束後,會繼續保持連線,直到超過idleTimeout值才會關閉連接。 connectionTimeout:和伺服器建立連線逾時,如果超過connectionTimeout值則會拋出SocketException異常。 maxConnec
Thumbnail
首先需要在pubspec.yaml文件中添加依賴。 宣告 SharedPreferences record = await SharedPreferences.getInstance(); 寫入 //字串資料 await record.setString(key, value); //
Thumbnail
首先需要在pubspec.yaml文件中添加依賴。 宣告 SharedPreferences record = await SharedPreferences.getInstance(); 寫入 //字串資料 await record.setString(key, value); //
Thumbnail
👨‍💻 簡介 最近想要透過小實作來撰寫筆記,達到做中學的效果,因此就來實作個小爬蟲順便結合前面學到的package做一個小複習。
Thumbnail
👨‍💻 簡介 最近想要透過小實作來撰寫筆記,達到做中學的效果,因此就來實作個小爬蟲順便結合前面學到的package做一個小複習。
Thumbnail
在這一課中,我們將學習如何在Python中使用requests模塊發送HTTP請求。 發送GET請求requests.get() 函數用於發送GET請求。
Thumbnail
在這一課中,我們將學習如何在Python中使用requests模塊發送HTTP請求。 發送GET請求requests.get() 函數用於發送GET請求。
Thumbnail
呼叫API,並透過API響應的內容取到需要的值
Thumbnail
呼叫API,並透過API響應的內容取到需要的值
追蹤感興趣的內容從 Google News 追蹤更多 vocus 的最新精選內容追蹤 Google News