1

I am implementing Link preview feature like WhatsApp, i.e

  1. Provided any link, fetch all its Html
  2. Crawl through Html, read all information
  3. Display text and images

WhatsApp Link Preview

Jsoup Library

I am successfully able to perform this using Jsoup library

Document doc = Jsoup.connect("http://www.techjuice.pk").userAgent("Mozilla").get();

It returns the html code of the page as a response.


Retrofit Library

Now I wanted to perform the same task using Retrofit

Retrofit retrofit = new Retrofit.Builder()
                    .build();
API api = retrofit.create(API.class);
Call<ResponseBody> call = api.crawlLink("http://techjuice.pk");
call.enqueue(new Callback<ResponseBody>() {
    @Override
    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
    }

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

API.class

public interface API {

    @GET
    Call<ResponseBody> crawlLink(@Url String url);

}

Exception

java.lang.IllegalStateException: Base URL required.

shanraisshan
  • 3,521
  • 2
  • 21
  • 44

1 Answers1

0

Unfortunatelly you can't change URL in Retrofit at Runtime in that way.

Try this tutorial: https://futurestud.io/tutorials/retrofit-2-how-to-change-api-base-url-at-runtime-2

or this answer: Set dynamic base url using Retrofit 2.0 and Dagger 2

Community
  • 1
  • 1
Leśniakiewicz
  • 874
  • 1
  • 10
  • 21