| | |
| | | import org.apache.http.impl.client.HttpClientBuilder; |
| | | import org.apache.http.util.EntityUtils; |
| | | import org.dromara.common.oss.entity.SynchronousRequest; |
| | | import org.dromara.common.oss.entity.VideoRequest; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.io.*; |
| | |
| | | } |
| | | |
| | | /** |
| | | * 上传同步 |
| | | * 上传同步 视频专网 |
| | | * @param url |
| | | * @param entity |
| | | * @return |
| | |
| | | } |
| | | |
| | | /** |
| | | * 上传同步 视频专网 |
| | | * @param url |
| | | * @param entity |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public static String sendPostRequest2(String url, VideoRequest entity) throws IOException { |
| | | org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build(); |
| | | HttpPost httpPost = new HttpPost(url); |
| | | |
| | | ContentType contentType = ContentType.create("multipart/form-data", StandardCharsets.UTF_8); |
| | | MultipartEntityBuilder builder = MultipartEntityBuilder.create(); |
| | | builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); |
| | | |
| | | // 添加MultipartFile参数 |
| | | builder.addBinaryBody("file", entity.getFile().getBytes(), ContentType.MULTIPART_FORM_DATA, entity.getFile().getOriginalFilename()); |
| | | |
| | | // 添加String参数 |
| | | builder.addTextBody("fileName", entity.getFileName(), contentType); |
| | | |
| | | HttpEntity multipart = builder.build(); |
| | | httpPost.setEntity(multipart); |
| | | |
| | | HttpResponse response = httpClient.execute(httpPost); |
| | | String responseBody = EntityUtils.toString(response.getEntity()); |
| | | System.out.println("Response: " + responseBody); |
| | | return responseBody; |
| | | } |
| | | |
| | | /** |
| | | * 上传同步2 |
| | | * @param url |
| | | * @param entity |
| | | * @return |
| | | * @throws IOException |
| | | */ |
| | | public static String sendPostRequestTwo(String url, SynchronousRequest entity) throws IOException { |
| | | org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build(); |
| | | HttpPost httpPost = new HttpPost(url); |
| | | |
| | | ContentType contentType = ContentType.create("multipart/form-data", StandardCharsets.UTF_8); |
| | | MultipartEntityBuilder builder = MultipartEntityBuilder.create(); |
| | | builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); |
| | | |
| | | // 添加MultipartFile参数 |
| | | builder.addBinaryBody("file", entity.getFile().getBytes(), ContentType.MULTIPART_FORM_DATA, entity.getFile().getOriginalFilename()); |
| | | |
| | | HttpEntity multipart = builder.build(); |
| | | httpPost.setEntity(multipart); |
| | | |
| | | HttpResponse response = httpClient.execute(httpPost); |
| | | String responseBody = EntityUtils.toString(response.getEntity()); |
| | | System.out.println("Response: " + responseBody); |
| | | return responseBody; |
| | | } |
| | | |
| | | /** |
| | | * 删除同步 |
| | | * @param url |
| | | // * @param parameter |