httpclient
HttpClient是一个客户端的HTTP通信实现库。HttpClient的目标是发送和接收HTTP报文
get请求的简单样例
public void testGet() throws IOException { //创建httpclient对象 CloseableHttpClient httpClient = HttpClients.createDefault(); //创建请求对象 HttpGet httpGet = new HttpGet("http://localhost:8080/user/shop/status"); //发送请求,接收结果 CloseableHttpResponse response = httpClient.execute(httpGet); //获取服务器返回码 int statusCode=response.getStatusLine().getStatusCode(); System.out.println("服务器的返回码为"+statusCode); HttpEntity entity=response.getEntity(); String body = EntityUtils.toString(entity); System.out.println("服务器的返回数据为"+body); //关闭资源 response.close(); httpClient.close(); }