首页 > 解决方案 > Web服务响应503时如何管理html代码

问题描述

我正在使用改造来使用 Web 服务,一切正常,但我想在 Web 服务响应 503 代码时处理 html 响应。

这是 html 响应,我想知道如何获取titleiframe src

Web 服务响应 503 时的 HTML 响应

调用网络服务的代码:

 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"
                }

标签: androidretrofit

解决方案


编辑:

通过使用 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 解析器是最好的?


推荐阅读