代码之家  ›  专栏  ›  技术社区  ›  depreston

web服务响应时如何管理html代码503

  •  0
  • depreston  · 技术社区  · 6 年前

    我使用改型来使用web服务,一切正常,但我希望在web服务响应503代码时处理html响应。

    标题 价值

    HTML response when web service response 503

    调用web服务的代码:

     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"
                    }
    
    2 回复  |  直到 6 年前
        1
  •  0
  •   Irfan    6 年前

    编辑:

    通过使用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();
    

    查看此链接了解更多详细信息 Which HTML Parser is the best?

        2
  •  0
  •   PRATEEK BHARDWAJ    6 年前
    @Override
    public void onResponse(Call<Model> call, Response<Model> response) {
        if (response.code() == 200) {
           // Do your work
        }
     if (response.code() == 503) {
    
        }
     else {
           // Handle other condition
        }
    }