从 OkHttp 响应主体解密 SSL 流量
Decyrpting SSL traffic from OkHttp response body
我正在开发一个应用程序,我使用 OkHttp, get the response data and extract the required data with Jsoup.
连接到一个网站
一切正常,直到我连接到不安全的 HTTP URL。当我连接到 HTTPS URL 时,响应已编码,我不知道如何对其进行解码。
我浏览了几个 Whosebug 线程来讨论这个特定问题以及 SSL 的工作原理,但没有任何好处。
这是我正在使用的一段代码:
private void startInternal() throws Exception {
Request request = new Request.Builder()
.url(att_link)
.get()
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0")
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
.addHeader("Accept-Language", "en-US,en;q=0.5")
.addHeader("Accept-Encoding", "gzip, deflate, br")
.addHeader("Connection", "keep-alive")
.addHeader("Referer", "https://www.abcdx.org/")
.addHeader("Upgrade-Insecure-Requests", "1")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (Exception e) {
runner.onError();
e.printStackTrace();
}
if (response != null) {
if (response.body() != null) {
obtainCookieAndGo(Objects.requireNonNull(response.body()).string());
} else {
runner.onError();
}
} else {
runner.onError();
}
}
预期输出
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><meta charset="utf-8" /><title>
</title><link href="images/favicon.png" rel="shortcut icon" /><link href="css/dashboard.css" rel="stylesheet" type="text/css" media="all" /><link href="css/font-awesome.css" rel="stylesheet" type="text/css" media="all" /><link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" media="all" /><link href="css/menu.css" rel="stylesheet" type="text/css" media="all" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/organictabs.jquery.js" type="text/javascript"></script>
<script src="tinymce3.x/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
</head>
<body>
<form method="post" action="./student-attendance.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="CMjQBN==" />
</div>
实际输出
��������������`I�%&/m�{J�J��t�`$ؐ@������iG#)�*��eVe]fx@
�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?"~��7N��O�<y��
�<M���L_~����I���ݻ߽wr���7O����o�x��w�7u�l����Yy��鋏ҏ�m�zt��������/�yu
`���u������GG�5��y6;z���,����>Z����w��E[����N���/�:OO�
�2��by�f�Y�E��.�E�lG��U���<k �]y�qY,ߦ�:?��bA����e1�����⣴���>j�U�N�
m�Ϲc�i�e�|Re�lL����2o�y�~�������]{�,�Y�}�QV�1h�ղ�ή�Z��<�E��F�E�_�o
这与 SSL 无关。
.addHeader("Accept-Encoding", "gzip, deflate, br")
您明确声称您支持各种内容编码(压缩),但您并未在您的代码中处理这些内容。如果您想获得简单的响应,请不要声称支持压缩响应。
我正在开发一个应用程序,我使用 OkHttp, get the response data and extract the required data with Jsoup.
连接到一个网站一切正常,直到我连接到不安全的 HTTP URL。当我连接到 HTTPS URL 时,响应已编码,我不知道如何对其进行解码。
我浏览了几个 Whosebug 线程来讨论这个特定问题以及 SSL 的工作原理,但没有任何好处。
这是我正在使用的一段代码:
private void startInternal() throws Exception {
Request request = new Request.Builder()
.url(att_link)
.get()
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:72.0) Gecko/20100101 Firefox/72.0")
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
.addHeader("Accept-Language", "en-US,en;q=0.5")
.addHeader("Accept-Encoding", "gzip, deflate, br")
.addHeader("Connection", "keep-alive")
.addHeader("Referer", "https://www.abcdx.org/")
.addHeader("Upgrade-Insecure-Requests", "1")
.build();
Response response = null;
try {
response = client.newCall(request).execute();
} catch (Exception e) {
runner.onError();
e.printStackTrace();
}
if (response != null) {
if (response.body() != null) {
obtainCookieAndGo(Objects.requireNonNull(response.body()).string());
} else {
runner.onError();
}
} else {
runner.onError();
}
}
预期输出
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head><meta charset="utf-8" /><title>
</title><link href="images/favicon.png" rel="shortcut icon" /><link href="css/dashboard.css" rel="stylesheet" type="text/css" media="all" /><link href="css/font-awesome.css" rel="stylesheet" type="text/css" media="all" /><link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" media="all" /><link href="css/menu.css" rel="stylesheet" type="text/css" media="all" />
<script src="js/jquery-1.7.2.min.js"></script>
<script src="js/organictabs.jquery.js" type="text/javascript"></script>
<script src="tinymce3.x/jscripts/tiny_mce/tiny_mce.js" type="text/javascript"></script>
</head>
<body>
<form method="post" action="./student-attendance.aspx" id="form1">
<div class="aspNetHidden">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="CMjQBN==" />
</div>
实际输出
��������������`I�%&/m�{J�J��t�`$ؐ@������iG#)�*��eVe]fx@
�흼��{���{���;�N'���?\fdl��J�ɞ!���?~|?"~��7N��O�<y��
�<M���L_~����I���ݻ߽wr���7O����o�x��w�7u�l����Yy��鋏ҏ�m�zt��������/�yu
`���u������GG�5��y6;z���,����>Z����w��E[����N���/�:OO�
�2��by�f�Y�E��.�E�lG��U���<k �]y�qY,ߦ�:?��bA����e1�����⣴���>j�U�N�
m�Ϲc�i�e�|Re�lL����2o�y�~�������]{�,�Y�}�QV�1h�ղ�ή�Z��<�E��F�E�_�o
这与 SSL 无关。
.addHeader("Accept-Encoding", "gzip, deflate, br")
您明确声称您支持各种内容编码(压缩),但您并未在您的代码中处理这些内容。如果您想获得简单的响应,请不要声称支持压缩响应。