API is sending one HTML page as response.
Currently i am receiving as ResponseBody
public interface DashBoardHtmlJsonAPI {
@FormUrlEncoded
@POST("/MobileDashbord")
Call<ResponseBody> getHtml(@Field("UserName") String username, @Field("Password") String password);
}
I want convert the responseBody to String and load the html to webview.
html = response.body().string();
After successful response above code return a blank string
I am not able to retrieve the html page as string.
Retrofit retrofit = new Retrofit.Builder().baseUrl(Constants.BASE_URL).addConverterFactory(ScalarsConverterFactory.create()).build();
DashBoardHtmlJsonAPI dashBoardHtmlJsonAPI = retrofit.create(DashBoardHtmlJsonAPI.class);
Call<ResponseBody> call = dashBoardHtmlJsonAPI.getHtml(userName,password);
call.enqueue(new Callback<ResponseBody>() {
@Override
public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
if (response.isSuccessful()){
String html="";
try {
html = response.body().string();
} catch (IOException e) {
e.printStackTrace();
}
loadWebView(html);
Log.i("WEBVIEW",response.toString());
Log.i("WEBVIEW",html);
}
else {
Log.i("WEBVIEW",response.body().toString());
}
}
@Override
public void onFailure(Call<ResponseBody> call, Throwable t) {
Log.i("WEBVIEW",t.getLocalizedMessage());
}
});
Can anybody help me?
You need to retrieve the content from body
try {
html = response.body().content();
} catch (IOException e) {
e.printStackTrace();
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.