I am implementing Link preview feature like WhatsApp, i.e
- Provided any link, fetch all its Html
- Crawl through Html, read all information
- Display text and images
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.