Commit 7c94bb90 by liulianglang

字符集

parent 87a2a701
......@@ -201,7 +201,7 @@ public class ForwardController {
if("undefined".equals(data)||"null".equals(data)){
data="{}";
}
data=URLDecoder.decode(data);
if("".equals(data)){
data="{}";
}
......@@ -209,7 +209,7 @@ public class ForwardController {
JSONObject jsonObject = JSONObject.parseObject(data);
Map jsonToMap = JSONObject.parseObject(jsonObject.toJSONString());
System.out.println("data:=="+jsonToMap);
String s = HttpUtil.uploadFile(host + url, file, file.getName(), headers, jsonToMap);
String s = HttpUtil.uploadFile(host + url, file, "file", headers, jsonToMap);
return JSONObject.parseObject(s, R.class);
} catch (Exception e) {
e.printStackTrace();
......
......@@ -539,10 +539,12 @@ public class HttpUtil {
}
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setCharset(StandardCharsets.UTF_8);
ContentType contentType=ContentType.create("text/plain",Charset.forName("UTF-8"));
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);//加上此行代码解决返回中文乱码问题
builder.addBinaryBody(fileParamName, file.getInputStream(), ContentType.MULTIPART_FORM_DATA, fileName);// 文件流
for (Map.Entry<String, String> e : otherParams.entrySet()) {
builder.addTextBody(e.getKey(), String.valueOf(e.getValue()));// 类似浏览器表单提交,对应input的name和value
// builder.addTextBody(e.getKey(), String.valueOf(e.getValue()));// 类似浏览器表单提交,对应input的name和value
builder.addTextBody(e.getKey(), String.valueOf(e.getValue()),contentType);
}
HttpEntity entity = builder.build();
httpPost.setEntity(entity);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment