一、请求方法
Form form = Form.form();
for (String s : paramMap.keySet()) {
form.add(s, paramMap.get(s));
}
try {
String content = Request.Post("x.x.x.x:c/x.htm")
.connectTimeout(2000)
.bodyForm(form.build(), Charset.forName("utf-8"))
.execute().returnContent().asString();
JSONObject json = JSONObject.parseObject(content);
} catch (Exception e) {
}
return null;
![](https://img-blog.csdnimg.cn/53afe9b436af4e0d8f33df9bd2f320c9.png)
二、解决
1、创建表单时明确编码方式
Form form = Form.form();
for (String s : paramMap.keySet()) {
form.add(s, paramMap.get(s));
}
try {
String content = Request.Post("x.x.x.x:c/x.htm")
.connectTimeout(2000)
.bodyForm(form.build(), Charset.forName("utf-8"))
.execute().returnContent().asString();
JSONObject json = JSONObject.parseObject(content);
} catch (Exception e) {
}
return null;
2、请求头中添加编码方式
Form form = Form.form();
for (String s : paramMap.keySet()) {
form.add(s, paramMap.get(s));
}
try {
String content = Request.Post("x.x.x.x:c/x.htm")
.connectTimeout(2000)
.bodyForm(form.build(), Charset.forName("utf-8"))
.setHeader("Content-Type", ContentType.create("application/x-www-form-urlencoded","utf-8").toString())
.execute().returnContent().asString();
JSONObject json = JSONObject.parseObject(content);
} catch (Exception e) {
}
return null;