使用UriBuilder构建访问地址
URIbuilder builder= URIbuilder(url);
builder.addParameter("userName":username);
builder.addParameter("pwd",pwd);
URI uri = builder.build();
HttpGet httpGet = new HttpGet(uri);
调用远程统一登录接口的时候加密后的密码在请求的时候被自动转义了%变成了%25
http://127.0.0.1/getInfo?name=atysy&pwd=nhdxJ7890%3D
http://127.0.0.1/getInfo?name=atysy&pwd=nhdxJ7890%253D
查阅资料
UriComponentsBuilder builder = UriComponentsBuilder
.fromHttpUrl("http://xxx.com/image-checker/train_mean.txt").queryParam("Expires", "3678172563").queryParam("Signature", "2FqOFfzePCjESlKMqiGc9V8C9Es%3D");
HttpGet httpGet = new HttpGet(builder.toString());
构建uri方式主要有:
StringBuffer/StringBuilder,拼接字符(无效)
URLBuilder生成URI (无效)
UriComponent构建uri
UriComponentBuilder
发现使用UriComponentBuilder方式没有自动转码问题