FastHttpClientOkHttp 简易封装工具
FastHttpClient 是简易封装 OkHttp 的工具(需要jdk8以上),高效使用http(s) post get 。
用法
1.同步的get
FastHttpClient.get(). url(url). addParams("userName", "icecool"). addParams("password", "111111"). build(). execute();
2.同步的post
FastHttpClient.post(). url(url). addParams("userName", "icecool"). addParams("password", "111111"). build(). execute();
3.异步的get
FastHttpClient.get(). url(url). addParams("userName","icecool"). addParams("password", "111111"). build(). executeAsync(new Callback() { @Override public void onFailure(Call call, Exception e, int id) { //TODO } @Override public void onResponse(Call call,Response response, int id) { try { System.out.println(response.body().string()); } catch (IOException e) { } } });
4.异步的post
FastHttpClient.post(). url(url). addParams("userName","icecool"). addParams("password", "111111"). build(). executeAsync(new Callback() { @Override public void onFailure(Call call, Exception e, int id) { //TODO } @Override public void onResponse(Call call,Response response, int id) { try { System.out.println(response.body().string()); } catch (IOException e) { } } });
5.异步下载文件
FastHttpClient.get(). url("http://e.hiphotos.baidu.com/image/pic/item/faedab64034f78f0b31a05a671310a55b3191c55.jpg"). build().addNetworkInterceptor(new DownloadFileInterceptor(){ @Override public void updateProgress(long downloadLenth, long totalLength, boolean isFinish) { System.out.println("updateProgress downloadLenth:"+downloadLenth+ ",totalLength:"+totalLength+",isFinish:"+isFinish); } }). executeAsync(new DownloadFileCallback("/tmp/tmp.jpg") {//save file to /tmp/tmp.jpg @Override public void onFailure(Call call, Exception e, int id) { e.printStackTrace(); } @Override public void onSuccess(Call call, File file, int id) { super.onSuccess(call, file, id); System.out.println("filePath:"+file.getAbsolutePath()); } @Override public void onSuccess(Call call, InputStream fileStream, int id) { System.out.println("onSuccessWithInputStream"); } }); Thread.sleep(50000);
6.上传文件
byte[] imageContent=FileUtil.getBytes("/tmp/test.png"); response = FastHttpClient.post(). url(url). addFile("file1", "a.txt", "123"). addFile("file2", "b.jpg", imageContent). build(). connTimeOut(10000). execute(); System.out.println(response.body().string());
7.https get
Response response = FastHttpClient.get().url("https://kyfw.12306.cn/otn/"). build() .execute(); System.out.println(response.body().string());
8.https post
Response response = FastHttpClient.post().url("https://kyfw.12306.cn/otn/"). build() .execute(); System.out.println(response.body().string());
评论
TextBlob简易 Pythonic 文本处理工具
TextBlob 是一款 Pythonic 的文本处理工具,用于处理文本数据,它提供了一个简单的 A
TextBlob简易 Pythonic 文本处理工具
0
Gummi简易 LaTeX 编辑工具
Gummi是一个简易LaTeX编辑工具,具备实时预览、语法高亮、BibTex支持、导出到PDF、纠错/拼写检查、预设模版等功能。Ubuntu用户可以通过这个PPA来安装:sudoapt-add-rep
Gummi简易 LaTeX 编辑工具
0
TextBlob简易 Pythonic 文本处理工具
TextBlob是一款Pythonic的文本处理工具,用于处理文本数据,它提供了一个简单的API,用于潜入常见的自然语言处理(NLP)任务,如词性标注、名词短语提取、情感分析、分类、翻译等。特性:名词
TextBlob简易 Pythonic 文本处理工具
0
XCoderXcode 工具的 Ruby 封装
Xcoder是Xcode工具的Ruby封装起,提供项目和工作空间的解析和部分写的支持。支持操作密钥链,打包和上传工件到Testflight并提供profile管理。
XCoderXcode 工具的 Ruby 封装
0
hmtool简易的通用工具集
项目已更名为pacebox基于hmtool封装的开源工具包。目前已正式发布springboot和springcloud版集成demo使用。特点:1:支持多kafka配置、可配置多个kafka生产消费调
hmtool简易的通用工具集
0