Retrofit Get String Response
Is it possible to recieve only String response using Retrofit library? I have a situation where I need to add Query on my link so that link is looking like : localhost//Register?ha
Solution 1:
You can get the response from api and convert it to string like this:
publicinterfaceRetrofitService{
@GET("/users")
Call<ResponseBody> listRepos();//function to call api
}
RetrofitService service = retrofit.create(RetrofitService.class);
Call<ResponseBody> result = service.listRepos(username);
result.enqueue(new Callback<ResponseBody>() {
@Override
publicvoidonResponse(Response<ResponseBody> response) {
try {
System.out.println(response.body().string());//convert reponse to string
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
publicvoidonFailure(Throwable t) {
e.printStackTrace();
}
});
Post a Comment for "Retrofit Get String Response"