package com.utils;
import cn.hutool.core.util.StrUtil;
public class BuildReqUrl {
private boolean isHasUrl = false;
private StringBuffer reqUrl;
public BuildReqUrl(String str) {
this.isHasUrl = true;
this.reqUrl = new StringBuffer(str);
}
public BuildReqUrl() {
this.reqUrl = new StringBuffer();
}
public BuildReqUrl set(String name,String value) {
if(this.isHasUrl)
reqUrl.append(!StrUtil.containsAny(reqUrl, "?") ? "?" : "&");
else
reqUrl.append(reqUrl.length() == 0 ? "" : "&");
reqUrl.append(name + "=" + value);
return this;
}
@Override
public String toString() {
return reqUrl.toString();
}
public static void main(String[] args) {
String reqUrl = new BuildReqUrl("https://www.toolnb.com/tools/xiantiaozi.html")
.set("param1", "123")
.set("param2", DigestUtil.md5Hex(
new BuildReqUrl()
.set("param1", "456")
.set("param2", "789")
.toString())
.toUpperCase())
.toString();
String reqResult = HttpUtil.get(reqUrl, 3 * 60 * 1000);
System.out.println(reqResult);
Result result = JSONUtil.toBean(reqResult, Result.class);
}
}
09-03
7632
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-04
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交