| | |
| | | // * @param parameter |
| | | * @throws Exception |
| | | */ |
| | | public static void sendDeleteRequest(String url, String parameter) throws Exception { |
| | | // 拼接URL和参数 |
| | | String deleteUrl = url + "/" + parameter; |
| | | // public static void sendDeleteRequest(String url, String parameter) throws Exception { |
| | | // // 拼接URL和参数 |
| | | // String deleteUrl = url + "/" + parameter; |
| | | // |
| | | // // 创建URL对象和HttpURLConnection对象 |
| | | // URL obj = new URL(deleteUrl); |
| | | // HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
| | | // |
| | | // // 设置请求方法为DELETE |
| | | // con.setRequestMethod("DELETE"); |
| | | // |
| | | // // 发送请求并获取响应 |
| | | // int responseCode = con.getResponseCode(); |
| | | // BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
| | | // String inputLine; |
| | | // StringBuffer response = new StringBuffer(); |
| | | // while ((inputLine = in.readLine()) != null) { |
| | | // response.append(inputLine); |
| | | // } |
| | | // in.close(); |
| | | // |
| | | // // 打印响应结果 |
| | | // System.out.println("Response Code : " + responseCode); |
| | | // System.out.println("Response : " + response.toString()); |
| | | // } |
| | | public static String sendDeleteRequest(String url, String ossId) throws IOException { |
| | | org.apache.http.client.HttpClient httpClient = HttpClientBuilder.create().build(); |
| | | HttpPost httpPost = new HttpPost(url); |
| | | |
| | | // 创建URL对象和HttpURLConnection对象 |
| | | URL obj = new URL(deleteUrl); |
| | | HttpURLConnection con = (HttpURLConnection) obj.openConnection(); |
| | | MultipartEntityBuilder builder = MultipartEntityBuilder.create(); |
| | | builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE); |
| | | |
| | | // 设置请求方法为DELETE |
| | | con.setRequestMethod("DELETE"); |
| | | // 添加MultipartFile参数 |
| | | // builder.addBinaryBody("file", entity.getFile().getBytes(), ContentType.MULTIPART_FORM_DATA, entity.getFile().getOriginalFilename()); |
| | | |
| | | // 发送请求并获取响应 |
| | | int responseCode = con.getResponseCode(); |
| | | BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); |
| | | String inputLine; |
| | | StringBuffer response = new StringBuffer(); |
| | | while ((inputLine = in.readLine()) != null) { |
| | | response.append(inputLine); |
| | | } |
| | | in.close(); |
| | | // 添加String参数 |
| | | builder.addTextBody("ossId", ossId, ContentType.TEXT_PLAIN); |
| | | |
| | | // 打印响应结果 |
| | | System.out.println("Response Code : " + responseCode); |
| | | System.out.println("Response : " + response.toString()); |
| | | 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; |
| | | } |
| | | } |
| | | |