package startDemo.controller;
import java.util.Date;
import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class HutoolUtil {
public static void main(String[] args) {
HutoolUtil.testHutoolPost("123");
}
public static void testHutoolGet() {
String getResult = HttpUtil
.createGet("https://tcc.taobao.com/cc/json/mobile_tel_segment.htm?tel=15677386236")
.execute()
.charset("gbk")
.body();
log.info("getResult:"+getResult);
}
public static void testHutoolPost(String cameraId) {
JSONObject jsonObject = JSONUtil.createObj();
jsonObject.put("cameraId", cameraId);
// jsonObject.put("startTime", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
jsonObject.put("callback", "http://www.baidu.com");
String postResult = HttpRequest
.post("www.jiekou.com")
.header("Content-Type","application/json")
.body(jsonObject)
.execute()
.body();
log.info("postResult:"+postResult);
}
}
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>1.2.4</version>
</dependency>
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>4.1.0</version>
</dependency>