<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
引入依赖
import cn.hutool.json.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.httpclient.methods.GetMethod;
import java.net.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
import java.util.Map;
get请求
HttpClient client = new HttpClient();
GetMethod getMethod = new GetMethod("http://192.168.3.188/wynet/ship/getNet?access_token="+access_token);
client.executeMethod(getMethod);
byte[] response1 = getMethod.getResponseBody();
String result1 = new String(response1,"UTF8");
JSONObject js = new JSONObject(result1);
System.out.println(js);
post请求
HttpClient client = new HttpClient();
PostMethod postMethod= new PostMethod("http://192.168.3.188/wynet/ship/getNet?access_token="+access_token);
client.executeMethod(postMethod);
byte[] response1 = postMethod.getResponseBody();
String result1 = new String(response1,"UTF8");
JSONObject js = new JSONObject(result1);
System.out.println(js);