flutter 第三方库Dio,设置网络请求、拦截器、cookie

1、dart库搜索dio,按文档配置
2、网络请求
	get
		Response response = await Dio().get(url);
      	print(json.decode(response));
  	
  	post
      	Response response = await Dio().post(url2, data:{'key':'4a8edfc8ac5eae9b0c5bf08157abba96'});
    	print(json.decode(response));

代码示例:

  var url="http://api.tianapi.com/txapi/ncov/index?key=4a8edfc8ac5eae9b0c5bf08157abba96";
  get() async{
     Response response = await Dio().get(url);
      print(response);
  }
  
  var url2="http://api.tianapi.com/txapi/ncov/index";
  post() async
  {
   Response response = await Dio().post(url2, data:{'key':'4a8edfc8ac5eae9b0c5bf08157abba96'});
    print(response);
  }
发布了670 篇原创文章 · 获赞 4 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/weixin_43294560/article/details/105615078