| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- import java.io.OutputStream;
- import java.net.HttpURLConnection;
- import java.net.URL;
- import java.nio.charset.StandardCharsets;
- public class TestModelTransformSave {
- public static void main(String[] args) {
- try {
- // 模拟前端发送的模型变换数据
- String json = "{
- \"id\": 111,
- \"coordinates\": \"119.14413000000002,25.867905,-1.165372999387529\",
- \"rotationX\": 0,
- \"rotationY\": 0,
- \"rotationZ\": 260,
- \"scaleX\": 1,
- \"scaleY\": 1,
- \"scaleZ\": 1
- }";
-
- // 后端API地址
- URL url = new URL("http://localhost:8080/watershed/model");
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
-
- // 设置请求方法和头信息
- connection.setRequestMethod("PUT");
- connection.setRequestProperty("Content-Type", "application/json");
- connection.setRequestProperty("Authorization", "Bearer your-token-here");
- connection.setDoOutput(true);
-
- // 发送数据
- try (OutputStream os = connection.getOutputStream()) {
- byte[] input = json.getBytes(StandardCharsets.UTF_8);
- os.write(input, 0, input.length);
- }
-
- // 获取响应
- int responseCode = connection.getResponseCode();
- System.out.println("响应代码: " + responseCode);
-
- if (responseCode == HttpURLConnection.HTTP_OK) {
- System.out.println("模型变换数据保存成功!");
- } else {
- System.out.println("保存失败,响应代码: " + responseCode);
- }
-
- connection.disconnect();
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- }
|