一、get,这里请求的是百度官网
import org.apache.http.HttpEntity;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import java.io.IOException;
public class HttpClientUtils2 {
public static void main(String[] args) throws ClientProtocolException, IOException {
get("https://www.baidu.com/?tn=49055317_11_hao_pg");
}
public static void get(String URL) throws IOException {
//创建一个默认链接
CloseableHttpClient httpClient = HttpClients.createDefault();
HttpGet httpGet = new HttpGet(URL);
CloseableHttpResponse response = httpClient.execute(httpGet);
//获取状态码
int statusCode = response.getStatusLine().ge