android - Web服务响应503时如何管理html代码
问题描述
我正在使用改造来使用 Web 服务,一切正常,但我想在 Web 服务响应 503 代码时处理 html 响应。
这是 html 响应,我想知道如何获取title或iframe src值
调用网络服务的代码:
ParameterCall parameterCall = new ParameterCall();
parameterCall.setDeviceType(Constants.DEVICE_TYPE);
Util.getRetrofit(this).parameter(parameterCall).enqueue(new Callback<ParameterResponse>() {
@Override
public void onResponse(Call<ParameterResponse> call, Response<ParameterResponse> response) {
if (response.isSuccessful() && response.body().getStatus() == 1) {
//do smt
}else if(response.code() == 503){
//Here I want to show a dialog if html structure shows me the word "MANTENIMIENTO" in "body iframe"
}
解决方案
编辑:
通过使用 jsoup 库,您可以做到这一点,https://jsoup.org可以完成这项工作
代码示例如下
String htmlString = "<html><head><title>My title</title></head>"
+ "<body>Body content</body></html>";
Document doc = Jsoup.parse(htmlString);
String title = doc.title();
查看此链接以获取更多详细信息哪个 HTML 解析器是最好的?
推荐阅读
- python - 如何将字典的键值从随机数更改为连续整数?
- c++ - 使用 C++ 时如何添加带空格的名称?
- javascript - 基于选择多选下拉显示和隐藏的Angular-6无法正常工作
- javascript - 如何在 nuxt 中为 dotenv 设置自定义路径
- matlab - matlab中三角格的邻接矩阵
- android - 我们可以在android中自定义WebView吗
- html - 未在 Angular Material Table 上选择元素时返回 false
- php - 什么时候全局函数不是可调用的?
- deep-learning - 为什么我在 cartpole 上的 DQN 不收敛?
- node.js - 无法在 MERN 堆栈 Web 应用程序中通过 axios 发布图像