From 526e6112c1a1968664ffdc47fe56feb36e2c428d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=96=AF=E9=9B=85?= <435508900@qq.com> Date: Tue, 19 Sep 2023 04:02:51 +0000 Subject: [PATCH 1/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=2020200340507=E9=99=88?= =?UTF-8?q?=E6=96=AF=E9=9B=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- "20200340507\351\231\210\346\226\257\351\233\205/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20200340507\351\231\210\346\226\257\351\233\205/.keep" diff --git "a/20200340507\351\231\210\346\226\257\351\233\205/.keep" "b/20200340507\351\231\210\346\226\257\351\233\205/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From 8b5ea8ca70774e28e7a55a0f8a9848c070e89a9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=96=AF=E9=9B=85?= <435508900@qq.com> Date: Tue, 19 Sep 2023 04:03:26 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20=E7=88=AC=E8=99=AB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../\347\210\254\350\231\253/.keep" | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 "20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/.keep" diff --git "a/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/.keep" "b/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/.keep" new file mode 100644 index 0000000..e69de29 -- Gitee From b6facd6ef3c2c681109b56e1640a62a74282ca1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=96=AF=E9=9B=85?= <435508900@qq.com> Date: Tue, 19 Sep 2023 04:05:06 +0000 Subject: [PATCH 3/3] =?UTF-8?q?=E7=88=AC=E8=99=AB=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 陈斯雅 <435508900@qq.com> --- .../\347\210\254\350\231\253/PaChong.java" | 34 +++++++++++++++++++ .../log4j.properties" | 6 ++++ 2 files changed, 40 insertions(+) create mode 100644 "20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/PaChong.java" create mode 100644 "20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/log4j.properties" diff --git "a/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/PaChong.java" "b/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/PaChong.java" new file mode 100644 index 0000000..47d4e40 --- /dev/null +++ "b/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/PaChong.java" @@ -0,0 +1,34 @@ +package pachong.test; + +import org.apache.http.HttpEntity; +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; + + +public class PaChong { + public static void main(String[] args) throws Exception { + // 1. 打开浏览器 : 创建HttpClient对象 + CloseableHttpClient httpClient = HttpClients.createDefault(); + + // 2. 输入网址 : 发起get请求创建HttpGet对象 + HttpGet httpGet = new HttpGet("https://www.example.com"); + + // 3. 按回车,发起请求,返回响应 : 使用httpClient对象发起请求 + CloseableHttpResponse response = httpClient.execute(httpGet); + + // 4. 解析响应,获取数据 + if (response.getStatusLine().getStatusCode()==200){ + // 拿到响应体 + HttpEntity httpEntity = response.getEntity(); + // 解析响应体,拿到静态页面的数据,将获取到的数据装入string中 + String content = EntityUtils.toString(httpEntity, "utf-8"); + + // 打印content 查看效果 + // 快捷键输入 idea:sout 按enter; eclipse : syso 按alt+/ 。 + System.out.println(content); + } + } +} \ No newline at end of file diff --git "a/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/log4j.properties" "b/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/log4j.properties" new file mode 100644 index 0000000..4ec95cd --- /dev/null +++ "b/20200340507\351\231\210\346\226\257\351\233\205/\347\210\254\350\231\253/log4j.properties" @@ -0,0 +1,6 @@ +1og4j.rootLogger =DEBUG,A1 +log4j.logger.cn.itcast=DEBUG + +log4j.appender.A1=org.apache.log4j.ConsoleAppender +log4j.appender.A1.layout=org.apache.log4j.PatternLayout +log4j.appender.A1.layout.ConversionPattern=%-d{yyyy-MW-dd HH:mm:Ss,SS5)[%t][%c]-[%p] %m%n -- Gitee