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);
}
}
06-22
1434