I use httpClient, teacher's print
pom will add the
Org. Apache. Httpcomponents Httpclient 4.5.2 & lt;/version> Org. Slf4j & lt;/groupId> Slf4j - log4j12 & lt;/artifactId> 1.7.25 & lt;/version>
The resource under the log4j properties (name right)
Log4j. Appender. The CONSOLE=org. Apache. Log4j. ConsoleAppender
Log4j rootLogger=Error, m
Log4j. Appender. M=org. Apache. Log4j. ConsoleAppender
Log4j. Appender. M.l ayout=org.. Apache log4j. PatternLayout
Log4j. Appender. M.l ayout. ConversionPattern=% d {MM - dd yyyy - HH: MM: ss} % - 5 p % c {1} : % L - % m % n
Then a simple main method, log what all don't print, video in print, but I am also copy him
Public class SikiHttpClientDemo {
Public static void main (String [] args) throws IOException {
CloseableHttpClient client=HttpClients. CreateDefault ();
HttpGet get=new HttpGet (" http://www.sikiedu.com/");
//imitation chorm request, some sites will be shielded httpclient, Java keywords such as
Get. SetHeader (" the user-agent ", "Mozilla/5.0 (Windows NT 10.0; Win64. X64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36 ");
CloseableHttpResponse response=client. The execute (get);
HttpEntity entity=response. GetEntity ();
System. The out. Println (EntityUtils. ToString (entity, "utf-8"));
}
}