String url = "http://localhost:831/ruoyi/ecr/productinfo/findByFldOrderCode";
String charset = "UTF-8";
JSONObject jsonObject = new JSONObject();
jsonObject.put("fldOrderCode","2022-JM-Q104");
jsonObject.put("fldReUnid","string");
jsonObject.put("pageNum",1);
jsonObject.put("pageSize",10);
String content = jsonObject.toJSONString();
HttpHost proxy = new HttpHost("127.0.0.1",8888);
RequestConfig requestConfig = RequestConfig.custom().setProxy(proxy).build();
CloseableHttpClient client = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
HttpPost post = new HttpPost(url);
post.setHeader("Content-Type", "application/json;charset=UTF-8");
StringEntity se = null;
try {
se = new StringEntity(content,charset);
se.setContentType("application/json");
post.setEntity(se);
CloseableHttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
String resData = EntityUtils.toString(response.getEntity());
System.out.println(resData);
client.close();
} catch (Exception e) {
e.printStackTrace();
}
public ResultData openFormUpload(@RequestParam Map<String, Object> params,
@RequestParam("file") MultipartFile file) throws IOException {
RestTemplate restClient = new RestTemplate();
String uploadUrl = formDomain;
MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
param.add("instanceId", params.get("instanceId"));
param.add("sectionId", params.get("sectionId"));
param.add("loginName", params.get("loginName"));
param.add("langType", params.get("langType"));
param.add("isAboard", params.get("isAboard"));
String fileName = file.getOriginalFilename();
String filePath = this.getClass().getResource("/").getPath() + fileName;
File tempFile = new File(filePath);
file.transferTo(tempFile);
FileSystemResource resource = new FileSystemResource(tempFile);
param.add("file", resource);
HttpHeaders headers = new HttpHeaders();
MediaType type = MediaType.parseMediaType("multipart/form-data;charset=UTF-8");
headers.setContentType(type);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<MultiValueMap<String, Object>>(param, headers);
String result = null;
try {
result = restClient.postForObject(uploadUrl, requestEntity, String.class);
JSONObject jsonObject = JSONObject.parseObject(result);
JSONObject data = jsonObject.getObject("data", JSONObject.class);
return ResultDataUtil.buildSuccess("200","操作成功!",data);
} catch (RestClientException e) {
return ResultDataUtil.buildError("201","调用接口失败!",e.getMessage());
} finally {
tempFile.delete();
}
}