0

I have a request to my server that the response is an HTML type like this:

<!DOCTYPE html>
<html>
    <head>
        <title>info starter</title>
    </head>
    <body>
        <!DOCTYPE html>
        <html lang="en">
            <head>
                <meta charset="UTF-8">
                <title>بازی نما</title>
                <style>
    }
      } }
    body{margin: 0;direction: rtl; font-family: myFont;font-size: 16px;padding: 1em 2em;background: url('https://bazinama.vasapi.click/static/bazinama-files/images/boundry.jpg') top center;color: #fff;}.coins{float: left;font-size: 1.5em;margin-top: -0.2em;}.coin-img{width: 1.5em;margin: -0.1em 0.5em;float: left;animation: coin 1s infinite linear;-webkit-animation: coin 1s infinite linear;-moz-animation: coin 1s infinite linear;}.row{margin: 2em 0;}p{line-height: 2.4em !important;}.title{text-align: center;margin-bottom: 1.5em;}.title .bold{font-size: 1.5em;color: #ffc800;}.box{background: rgba(11, 111, 251, 0.9);padding: 1em;border-radius: 1em;-webkit-border-radius: 1em;-moz-border-radius: 1em;margin: 2em 0;}.mobile-icon{width: 70px;float: right;}
    </style>
            </head>
            <body>
                <h2 class="title">
                    <span class="bold"> استارتر،</span>، پلتفرم حمایت از بازی های ایرانی و بازی سازی ملی است.
                </h2>
                <p>گیمرها، شرکت ها و تیم هپردازند،. </p>
            </body>
        </html>
    </body>
</html>

I set my request with Retrofit like this:

  @Headers("Accept: text/html")
  @GET("pages/Bazinamamag/starter/")
  Call<ResponseBody> getContactUsInfo();

And prepare the request like this:

@Override
  public void getContactUsInfo(@Nullable final LoadContactUsCallback callback) {
        final ApiService service = ServiceGenerator.createService(ApiService.class);

        service.getContactUsInfo().enqueue(new Callback<ResponseBody>() {
          @Override
          public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {

            try {
              Log.d(TAG, "onResponse: " + response.body().string());

              callback.onTasksLoaded(response.body().string());

            } catch (IOException e) {
              e.printStackTrace();
              Log.e(TAG, "onResponse: " + e.getMessage());
            }

          }

          @Override
          public void onFailure(Call<ResponseBody> call, Throwable t) {

            Log.e(TAG, "onFailure: " + t.getMessage());
            callback.onDataNotAvailable();

          }
        });
      }

But all the time can't get the HTML code that is in response and is ".

How can I get the html response?

Thank you.

Ehsan
  • 2,676
  • 6
  • 29
  • 56

1 Answers1

1

In case the Api you are consuming only delivers HTML, you could tell Retrofit to request HTML like:

@Headers("Accept: text/html")
@GET("myUrl")
Call<String> getContactUsInfo();

Also, be aware that in onResponse the response could be anything, wrap in it an isSuccessful like here: How to get Retrofit success response status codes.

Edit: looks like one would need a scalar converter for String data. This would be

compile 'com.squareup.retrofit2:converter-scalars:2.3.0'

like mentioned here.

sschrass
  • 7,014
  • 6
  • 43
  • 62