test:(测试使用Http发送)

dev
zhang xu 2024-05-30 22:05:56 +08:00
parent bd9aa73ffb
commit bacd7f18da
3 changed files with 104 additions and 12 deletions

View File

@ -4,6 +4,8 @@ import com.muyu.common.core.web.domain.BaseEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import java.util.Date;
@ -200,4 +202,26 @@ public class Enterprise extends BaseEntity {
public void setAddServiceId(Integer addServiceId) {
this.addServiceId = addServiceId;
}
@Override
public String toString(){
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
.append("id",getId())
.append("enterpriseName",getEnterpriseName())
.append("legalPerson",getLegalPerson())
.append("businessLicenseNumber",getBusinessLicenseNumber())
.append("establishmentDate",getEstablishmentDate())
.append("businessScope",getBusinessScope())
.append("address",getAddress())
.append("contactPhone",getContactPhone())
.append("email",getEmail())
.append("status",getStatus())
.append("registrationDate",getRegistrationDate())
.append("certification",getCertification())
.append("openServiceId",getOpenServiceId())
.append("addServiceId",getAddServiceId())
.toString();
}
}

View File

@ -11,21 +11,25 @@ import java.util.Date;
* @Created: 2024/5/26 20:31
*/
public class Vehicle extends BaseEntity {
private Long id; // 车辆唯一标识
private String vin; // 车辆识别号码VIN
private String brand; // 品牌
private String model; // 型号
private Long id;
// 车辆唯一标识
private String vin;
// 车辆识别号码VIN
private String brand;// 品牌
private String model;
private int manufactureYear; // 生产年份
private String bodyType; // 车身类型,例如"Sedan", "SUV"
private String color; // 车身颜色
private double engineCapacity; // 发动机排量,单位升
private String bodyType; // 车身类型,例如"Sedan", "SUV"
private String color; // 车身颜色
private double engineCapacity;
// 发动机排量,单位升
private String fuelType; // 燃油类型,例如"Petrol", "Diesel", "Electric"
private String transmission; // 变速器类型,例如"Automatic", "Manual"
private String driveType; // 驱动方式,例如"FWD", "RWD", "AWD"
private long mileage; // 行驶里程,单位公
private String transmission;// 变速器类型,例如"Automatic", "Manual"
private String driveType; // 驱动方式,例如"FWD", "RWD", "AWD"
private long mileage; // 行驶里程,单位公
private Date registrationDate; // 注册日期
private String registrationNumber; // 车牌号码
private String ownerId; // 所有者
private String registrationNumber; // 车牌号码
private String ownerId;
}

View File

@ -0,0 +1,64 @@
package com.muyu;
import cn.hutool.core.lang.hash.Hash;
import com.alibaba.fastjson2.JSON;
import lombok.extern.log4j.Log4j2;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.util.HashMap;
/**
* @ClassDescription:
* @JdkVersion: 17
* @Author: zhangxu
* @Created: 2024/5/30 21:55
*/
@Log4j2
public class Test {
public static void main(String[] args) {
// 测试
String url="http://115.159.67.205:10006/webhook/%E5%A2%9E%E5%80%BC%E6%9C%8D%E5%8A%A1";
HashMap<String, String> hashMap = new HashMap<>();
hashMap.put("entId","1");
hashMap.put("mysqlPort","port");
String json = JSON.toJSONString(hashMap);
// 创建连接与设置连接参数
URL urlObj=null;
try {
URL postMan = new URL(url);
HttpURLConnection httpConn = (HttpURLConnection) urlObj.openConnection();
httpConn.setRequestMethod("POST");
httpConn.setRequestProperty("Content-Type", "application/json");
httpConn.setDoOutput(true);
httpConn.setDoInput(true);
OutputStream outputStream = httpConn.getOutputStream();
outputStream.write(json.getBytes());
outputStream.flush();
if (httpConn.getResponseCode()!=200){
throw new Exception("调用服务端异常");
}
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
String resultData = bufferedReader.readLine();
log.info(resultData);
bufferedReader.close();
httpConn.disconnect();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}