@PostMapping("/face")
public ResponseResult playerFace(MultipartHttpServletRequest file, String phone, HttpServletRequest request) throws BusinessException {
// CloseableHttpClient httpClient = HttpClients.createDefault();
HttpHost proxy = new HttpHost("127.0.0.1", 8888, "http");//127.0.0.1:8888地址为fiddler的抓包代理地址
DefaultProxyRoutePlanner routePlanner = new DefaultProxyRoutePlanner(proxy);
CloseableHttpClient client = HttpClients.custom().setRoutePlanner(routePlanner).build();
MultipartFile multipartFile = file.getFile("face");
String result = "";
try {
String fileName = multipartFile.getOriginalFilename();
HttpPost httpPost = new HttpPost(PLAYER_URL_BASE + PLAYER_URL_FACE_POST);
// MultipartEntity entity =new MultipartEntity(HttpMultipartMode.);
// entity.addPart("face",new ByteArrayBody(multipartFile.getBytes(),"face"));
MultipartEntityBuilder builder = MultipartEntityBuilder.create();
// builder.setBoundary("--FaFlZG8h8pJDidGg6iAtbXzeqaaICWhXLR");
builder.addBinaryBody("face", multipartFile.getInputStream(), ContentType.create("image/jpeg", Consts.UTF_8), "face.jpg");// 文件流
HttpEntity entity = builder.build();
httpPost.setEntity(entity);
// HttpEntity entity = builder.build();
// httpPost.setHeader("X-Elephant-Token",getToken(phone));
httpPost.setHeader("X-Elephant-Source",PLAYER_SOURCE);
httpPost.setHeader("X-Elephant-Open-Id",phone);
HttpResponse response =client.execute(httpPost);
// httpPost.setHeader("Content-Length",String.valueOf(multipartFile.getSize()));
// HttpResponse response = HttpClientUtil.doPostFile(httpPost,entity,"",client);// 执行提交
HttpEntity responseEntity = response.getEntity();
if (responseEntity != null) {
// 将响应内容转换为字符串
result = EntityUtils.toString(responseEntity,"UTF-8");
}
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
} finally {
// try {
// httpClient.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
}
return ResponseResult.getResponse().setData(result);
}