39 lines
1.4 KiB
Java
39 lines
1.4 KiB
Java
import java.io.IOException;
|
|
import java.net.HttpURLConnection;
|
|
import java.net.URL;
|
|
import java.util.Scanner;
|
|
|
|
public class TestDeleteInspectionType {
|
|
public static void main(String[] args) {
|
|
try {
|
|
// 测试删除ID为1的检验类型
|
|
long inspectionTypeId = 1;
|
|
URL url = new URL("http://localhost:8080/system/inspection-type/" + inspectionTypeId);
|
|
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
|
connection.setRequestMethod("DELETE");
|
|
connection.setRequestProperty("Content-Type", "application/json");
|
|
connection.setRequestProperty("Accept", "application/json");
|
|
|
|
// 发送请求
|
|
int responseCode = connection.getResponseCode();
|
|
System.out.println("响应代码: " + responseCode);
|
|
|
|
// 读取响应
|
|
Scanner scanner;
|
|
if (responseCode >= 200 && responseCode < 300) {
|
|
scanner = new Scanner(connection.getInputStream());
|
|
} else {
|
|
scanner = new Scanner(connection.getErrorStream());
|
|
}
|
|
|
|
String response = scanner.useDelimiter("\\A").next();
|
|
System.out.println("响应内容: " + response);
|
|
|
|
scanner.close();
|
|
connection.disconnect();
|
|
|
|
} catch (IOException e) {
|
|
e.printStackTrace();
|
|
}
|
|
}
|
|
} |