JAVA调用HTTP接口
import cn.hutool.http.HttpResponse;
import com.alibaba.fastjson.JSONObject;
public static void main(String[] args) {
try {
String url = "http://ip:端口/message/push/V2";
Map<Object, Object> BodyParams = new HashMap<>();
BodyParams.put("username", 'ceshi');
BodyParams.put("age", 14);
String BodyParamsJson = JSONObject.toJSONString(BodyParams);
HttpResponse response = HttpRequest.post(url)
.header("Content-Type", "application/json")
.header("Connection", "keep-alive")
.body(BodyParamsJson)
.execute();
String ticketResult = response.body();
JSONObject json = JSONObject.parseObject(ticketResult);
System.out.println(ticketResult);
} catch (Exception e) {
System.out.println(e.toString());
}
}