final int _CONNECTTIMEOUT = 5000;
final int _RECEIVETIMEOUT = 3000;
//单例模式
static HttpManager _instance;
Dio _dio;
BaseOptions _options;
//单例模式,只创建一次实例
static HttpManager getInstance(){
if(null == _instance){
_instance = new HttpManager();
return _instance;
}
}
//构造函数
HttpManager(){
_options =new BaseOptions(
baseUrl: _BASEURL,
//连接时间为5秒
connectTimeout: _CONNECTTIMEOUT,
//响应时间为3秒
receiveTimeout: _RECEIVETIMEOUT,
//设置请求头
headers: {
"resource":"android"
},
//默认值是"application/json; charset=utf-8",Headers.formUrlEncodedContentType会自动编码请求体.
contentType: Headers.formUrlEncodedContentType,
//共有三种方式json,bytes(响应字节),stream(响应流),plain
responseType: ResponseType.json
);
_dio = new Dio(_options);
//设置Cookie
_dio.interceptors.add(CookieManager(CookieJar()));
//添加拦截器
_dio.interceptors.add(InterceptorsWrapper(
onRequest: (RequestOptions options){
print("在请求之前的拦截信息");
return options;
},
onResponse: (Response response){
print("在响应之前的拦截信息");
return response;
},
onError: (DioError e){
print("在错误之前的拦截信息");
return e;
}
));
}
//get请求方法
get(url,{data,options,cancelToken}) async{
Response response;
try{
response = await _dio.get(url,queryParameters: data,options: options,cancelToken: cancelToken);
print('getHttp response: $response');
}on DioError catch(e){
print('getHttp exception: $e');
formatError(e);
}
return response;
}
//post请求
post(url,{params,options,cancelToken}) async{
Response response;
try{
response = await _dio.post(url,queryParameters: params,options: options,cancelToken: cancelToken);
print('postHttp response: $response');
}on DioError catch(e){
print('postHttp exception: $e');
formatError(e);
}
return response;
}
//post Form请求
postForm(url,{data,options,cancelToken}) async{
Response response;
try{
response = await _dio.post(url,options: options,cancelToken: cancelToken,data: data);
print('postHttp response: $response');
}on DioError catch(e){
print('postHttp exception: $e');
formatError(e);
}
return response;
}
//下载文件
downLoadFile(urlPath,savePath) async{
Response response;
try{
response = await _dio.download(urlPath, savePath,onReceiveProgress: (int count,int total){
print('$count $total');
});
print('downLoadFile response: $response');
}on DioError catch(e){
print('downLoadFile exception: $e');
formatError(e);
}
return response;
}
//取消请求
cancleRequests(CancelToken token){
token.cancel("cancelled");
}
void formatError(DioError e) {
if (e.type == DioErrorType.CONNECT_TIMEOUT) {
print("连接超时");
} else if (e.type == DioErrorType.SEND_TIMEOUT) {
print("请求超时");
} else if (e.type == DioErrorType.RECEIVE_TIMEOUT) {
print("响应超时");
} else if (e.type == DioErrorType.RESPONSE) {
print("出现异常");
} else if (e.type == DioErrorType.CANCEL) {
print("请求取消");
} else {
print("未知错误");
}
}
}
调用时只需:
http.HttpManager.getInstance().get(‘’,params:{‘key’: ‘free’,‘msg’: ‘鹅鹅鹅’});
输出:
2020-04-17 14:42:30.252 25364-25460/com.example.flutter\_module.host I/flutter: 在请求之前的拦截信息
2020-04-17 14:42:31.145 25364-25460/com.example.flutter\_module.host I/flutter: 在响应之前的拦截信息
**自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。**
**深知大多数Android工程师,想要提升技能,往往是自己摸索成长或者是报班学习,但对于培训机构动则几千的学费,着实压力不小。自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!**
**因此收集整理了一份《2024年Android移动开发全套学习资料》,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。**
![img](https://img-blog.csdnimg.cn/img_convert/a0a99f3be80065d64e2b117d16a94179.png)
![img](https://img-blog.csdnimg.cn/img_convert/4f6d54041fb69ab161b2d95a419bd7d5.png)
![img](https://img-blog.csdnimg.cn/img_convert/b418b5818e14f87dec8b39c846f928ea.png)
![img](https://img-blog.csdnimg.cn/img_convert/e9f6fb29d528c0ce9c4617b499628d59.png)
![img](https://img-blog.csdnimg.cn/img_convert/eaed610cad841262c828783181e1b406.png)
![img](https://img-blog.csdnimg.cn/img_convert/bdc428abe4d05d68088b3a07e06cefe7.png)
![img](https://img-blog.csdnimg.cn/13f2cb2e05a14868a3f0fd6ac81d625c.png)
**既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,基本涵盖了95%以上Android开发知识点,真正体系化!**
**由于文件比较大,这里只是将部分目录大纲截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频,并且后续会持续更新**
**如果你觉得这些内容对你有帮助,可以添加V获取:vip204888 (备注Android)**
![img](https://img-blog.csdnimg.cn/img_convert/d552aeb8131b3b779857a15f0eab27fa.png)
# 最后
我一直以来都有整理练习大厂面试题的习惯,有随时跳出舒服圈的准备,也许求职者已经很满意现在的工作,薪酬,觉得习惯而且安逸。
不过如果公司突然倒闭,或者部门被裁减,还能找到这样或者更好的工作吗?
我建议各位,多刷刷面试题,知道最新的技术,每三个月可以去面试一两家公司,因为你已经有不错的工作了,所以可以带着轻松的心态去面试,同时也可以增加面试的经验。
我可以将最近整理的一线互联网公司面试真题+解析分享给大家,大概花了三个月的时间整理2246页,帮助大家学习进步。
> **由于篇幅限制,文档的详解资料太全面,细节内容太多,所以只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!以下是部分内容截图:**
![](https://img-blog.csdnimg.cn/img_convert/3f7ebd5cb67ccf6d6bc06349997f59c9.webp?x-oss-process=image/format,png)
![部分目录截图](https://img-blog.csdnimg.cn/img_convert/0ef029330e979e967caacac45cead430.webp?x-oss-process=image/format,png)
**一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
![img](https://img-blog.csdnimg.cn/img_convert/e42524bd7b25e7a18b954cc666fff721.png)
助大家学习进步。
> **由于篇幅限制,文档的详解资料太全面,细节内容太多,所以只把部分知识点截图出来粗略的介绍,每个小节点里面都有更细化的内容!以下是部分内容截图:**
[外链图片转存中...(img-UUmQsaN5-1712843837702)]
[外链图片转存中...(img-8fGPzBOE-1712843837703)]
**一个人可以走的很快,但一群人才能走的更远。不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎扫码加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
[外链图片转存中...(img-g1FITea9-1712843837703)]