2023-12-26|閱讀時間 ‧ 約 2 分鐘

[Flutter]Dio

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);
分享至
成為作者繼續創作的動力吧!
此專題是與APP程式設計相關的內容,包含:原生與跨平台。
從 Google News 追蹤更多 vocus 的最新精選內容從 Google News 追蹤更多 vocus 的最新精選內容

發表回應

成為會員 後即可發表留言
© 2024 vocus All rights reserved.