HttpClient httpclient = new HttpClient();
PostMethod post = new PostMethod(
Global.getConfig("gjss_address") + "接口");
post.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, "utf-8");
// Part数组装需要传第的参数和文件等
//文件定义方式
// if (StringUtils.isNotEmpty(creditReportThumb)) {
// creditReportThumbFilePart = new FilePart("microfiles", new File(creditReportThumb));
// creditReportThumbFilePart.setCharSet("utf-8");
// }
Part[] parts = { new StringPart("creditLevel",certificaterecord.getCreditLevel()!=null?certificaterecord.getCreditLevel():"","utf-8") };
MultipartRequestEntity entity = new MultipartRequestEntity(parts, post.getParams());
post.setRequestEntity(entity);
// httpclient.setTimeout(1000 * 50);
post.setRequestHeader(new Header("contentType","application/json;charset=utf-8"));
String result = "";
boolean success = true;
int code = httpclient.executeMethod(post);
// 拿到响应结果
result = new String(post.getResponseBody(), "UTF-8");
JSONObject jsonObject = JSONObject.parseObject(result);
success = (boolean) jsonObject.get("success");
// 可释放连接
post.releaseConnection();```
spring mvc跨平台传参数或文件(json)
最新推荐文章于 2023-12-05 19:05:31 发布