50 Star 105 Fork 56

山药蛋 / HttpUtils

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

HttpUtils是一个追求便捷的HttpRequest工具包

这是山药蛋的第一个开源项目,如有雷同不是巧合,欢迎拍砖。

HttpUtils能帮你做什么?

1.mapToQuery方法

如果你是一名web程序开发者,你一定拼过t=wxm2-login&lang=zh_CN&ajax=true这样的字符串吧。 例如:https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN。

	Map<String, String> queryMap = new HashMap<String, String>();
	queryMap.put("t", "wxm2-login");
	queryMap.put("lang", "zh_CN");
	queryMap.put("ajax", "true");
	String query = ParamUtils.mapToQuery(queryMap);

query就是拼接好的t=wxm2-login&lang=zh_CN&ajax=true

2.queryToMap方法
	String queryString = "t=wxm2-login&lang=zh_CN&ajax=true";
	Map<String, String> queryMap =  ParamUtils.queryToMap(queryString);

使用mapToQuery方法可以将t=wxm2-login&lang=zh_CN&ajax=true这样的QueryString转换为Map键值对

3. HttpRequest类使用
	HttpRequest request = new HttpRequest();
	String resultVal = request.addHeader("User-Agent", "Mozilla/5.0").addParam("username", "xxx@baidu.com").addParam("pwd", "123456").post("https://mp.weixin.qq.com/cgi-bin/login?lang=zh_CN");

	HttpRequest request = new HttpRequest();
	String resultVal = request.addHeader("User-Agent", "Mozilla/5.0").get("https://hao123.com");

链式调用方便快捷,一般场景中你只需要

	String resultVal = new HttpRequest().get("https://hao123.com");
4. 未完待续……

空文件

简介

在下一次更新后,将不再依赖commons-httpclient,并更名为http4j 展开 收起
Java
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/csen66/HttpUtils.git
git@gitee.com:csen66/HttpUtils.git
csen66
HttpUtils
HttpUtils
master

搜索帮助