I wanted to get the json string from version 2, but I don't need the object. please help get the line when call response.body () from the onResponse method.
public void getLoginResultFromWebservice(int customerID, String user, String pass) {
String action = "Login";
long timeMillis = System.currentTimeMillis();
String key = new String(Hex.encodeHex(DigestUtils.md5(G.HASH_KEY + timeMillis)));
String customerId = String.valueOf(customerID);
String username = user;
String password = pass;
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(G.URL_Webservice_Base)
.client(U.getClient())
.build();
Webservice webservice = retrofit.create(Webservice.class);
Call<String> call = webservice.getLoginResult(action,key,customerId,username,password);
call.enqueue(new Callback<String>() {
@Override
public void onResponse(Response<String> response) {
U.log(" ActivityLogin : OnResponse ");
U.log(" ActivityLogin : Result " + response.body().toString());
}
@Override
public void onFailure(Throwable t) {
U.log("ActivityLogin On Failure");
}
});
}
EDIT:
I found a solution:
new Retrofit.Builder()
.baseUrl(G.URL_Webservice_Base)
.addConverter(String.class, new ToStringConverter())
.build()
.create(Webservice.class);
ToStringConverter.class
public final class ToStringConverter implements Converter<String> {
@Override
public String fromBody(ResponseBody body) throws IOException {
return body.string();
}
@Override
public RequestBody toBody(String value) {
return RequestBody.create(MediaType.parse("text/plain"), value);
}
}
source
share