0

I'm using retrofit to consume web services and everything is OK but I'd like to handle html response when web service response 503 code.

This is the html response and I would like to know how to get title or iframe src value

HTML response when web service response 503

Code to call web service:

 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"
                }
Jorge Requez
  • 303
  • 4
  • 12

2 Answers2

0

Edit:

by using jsoup library you can do that, https://jsoup.org can do the job

Code Example is below

      String htmlString = "<html><head><title>My title</title></head>"
              + "<body>Body content</body></html>";

      Document doc = Jsoup.parse(htmlString);
      String title = doc.title();

check this link for more in detail Which HTML Parser is the best?

Irfan
  • 956
  • 9
  • 16
0
@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
    }
}
PRATEEK BHARDWAJ
  • 2,364
  • 2
  • 21
  • 35