正在显示
4 个修改的文件
包含
134 行增加
和
0 行删除
.gitignore
0 → 100644
1 | +HELP.md | ||
2 | +target/ | ||
3 | +!.mvn/wrapper/maven-wrapper.jar | ||
4 | +!**/src/main/** | ||
5 | +!**/src/test/** | ||
6 | + | ||
7 | +### STS ### | ||
8 | +.apt_generated | ||
9 | +.classpath | ||
10 | +.factorypath | ||
11 | +.project | ||
12 | +.settings | ||
13 | +.springBeans | ||
14 | +.sts4-cache | ||
15 | + | ||
16 | +### IntelliJ IDEA ### | ||
17 | +.idea | ||
18 | +*.iws | ||
19 | +*.iml | ||
20 | +*.ipr | ||
21 | + | ||
22 | +### NetBeans ### | ||
23 | +/nbproject/private/ | ||
24 | +/nbbuild/ | ||
25 | +/dist/ | ||
26 | +/nbdist/ | ||
27 | +/.nb-gradle/ | ||
28 | +build/ | ||
29 | +.idea | ||
30 | + | ||
31 | +### VS Code ### | ||
32 | +.vscode/ | ||
33 | +/logs/ | ||
34 | +/crawler/logs |
pom.xml
0 → 100644
1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
2 | +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" | ||
3 | + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
4 | + <modelVersion>4.0.0</modelVersion> | ||
5 | + <parent> | ||
6 | + <groupId>com.aukey</groupId> | ||
7 | + <artifactId>aukey-server-parent</artifactId> | ||
8 | + <version>1.0.0-SNAPSHOT</version> | ||
9 | + <relativePath/> <!-- lookup parent from repository --> | ||
10 | + </parent> | ||
11 | + <groupId>com.aukey.dws.ddh</groupId> | ||
12 | + <artifactId>check-https-utils</artifactId> | ||
13 | + <version>1.0.0</version> | ||
14 | + | ||
15 | + <properties> | ||
16 | + <maven.compiler.source>8</maven.compiler.source> | ||
17 | + <maven.compiler.target>8</maven.compiler.target> | ||
18 | + </properties> | ||
19 | + | ||
20 | + <dependencies> | ||
21 | + <dependency> | ||
22 | + <groupId>org.apache.commons</groupId> | ||
23 | + <artifactId>commons-lang3</artifactId> | ||
24 | + </dependency> | ||
25 | + <dependency> | ||
26 | + <groupId>commons-io</groupId> | ||
27 | + <artifactId>commons-io</artifactId> | ||
28 | + <version>2.6</version> | ||
29 | + </dependency> | ||
30 | + <dependency> | ||
31 | + <groupId>com.squareup.okhttp3</groupId> | ||
32 | + <artifactId>okhttp</artifactId> | ||
33 | + </dependency> | ||
34 | + </dependencies> | ||
35 | +</project> |
src/main/java/com/check/CheckHttpsUtils.java
0 → 100644
1 | +package com.check; | ||
2 | + | ||
3 | +import okhttp3.OkHttpClient; | ||
4 | +import okhttp3.Request; | ||
5 | +import org.apache.commons.io.FileUtils; | ||
6 | +import org.apache.commons.lang3.StringUtils; | ||
7 | + | ||
8 | +import java.io.File; | ||
9 | +import java.net.URL; | ||
10 | +import java.util.ArrayList; | ||
11 | +import java.util.HashSet; | ||
12 | +import java.util.List; | ||
13 | +import java.util.Set; | ||
14 | + | ||
15 | +/** | ||
16 | + * 测试https是否可以访问 | ||
17 | + * | ||
18 | + * @author weishaolei | ||
19 | + */ | ||
20 | +public class CheckHttpsUtils { | ||
21 | + | ||
22 | + public static void main(String[] args) throws Exception { | ||
23 | + //读取文件里的url | ||
24 | + URL resource = CheckHttpsUtils.class.getClassLoader().getResource("url.txt"); | ||
25 | + List<String> urls = FileUtils.readLines(new File(resource.getFile()), "utf-8"); | ||
26 | + | ||
27 | + List<String> errorList = new ArrayList(); | ||
28 | + Set<String> distinctUrl = new HashSet<>(urls); //去重 | ||
29 | + OkHttpClient client = new OkHttpClient(); | ||
30 | + for (String url : distinctUrl) { | ||
31 | + try { | ||
32 | + //去前后空格 | ||
33 | + String s = StringUtils.trimToNull(url); | ||
34 | + if (s == null) continue; | ||
35 | + //将http强转为https | ||
36 | + url = url.replace("http://", "https://"); | ||
37 | + url = url.replace("HTTP://", "https://"); | ||
38 | + //检测https的GET请求 | ||
39 | + Request request = new Request.Builder() | ||
40 | + .url(url) | ||
41 | + .get() | ||
42 | + .build(); | ||
43 | + client.newCall(request).execute(); | ||
44 | + System.out.println(url + " 成功支持HTTPS"); | ||
45 | + } catch (Exception e) { | ||
46 | + System.out.println(url + " 不支持HTTPS, 错误原因: " + e.getMessage()); | ||
47 | + errorList.add(url); | ||
48 | + } | ||
49 | + } | ||
50 | + if (errorList.isEmpty()) { | ||
51 | + System.out.println("所有域名都支持https."); | ||
52 | + } else { | ||
53 | + System.err.println("--------------------------------------------------------"); | ||
54 | + System.err.println("--------------- 无法访问https的所有域名如下 ----------------"); | ||
55 | + System.err.println("--------------------------------------------------------"); | ||
56 | + for (String s : errorList) { | ||
57 | + System.err.println(s); | ||
58 | + } | ||
59 | + } | ||
60 | + } | ||
61 | + | ||
62 | +} |
src/main/resources/url.txt
0 → 100644
-
请 注册 或 登录 后发表评论