How to capture raw/plain text response from the server


How to capture raw/plain text response from the server



I'm currently using Retrofit 1
enter image description here



I'm trying to find away to capture raw/plaintext response from server but not sure how to retrieve it.



This where i initialize it


@POST(ApplicationConstants.USER_URL+"/resendActivationEmail")
void resendEmail(@Body String email, ResponseCallback result);



and here's where i implement it.


userServiceApi.resendEmail(email, new ResponseCallback() {
@Override
public void success(Response response) {
LogHelper.debug("");
}

@Override
public void failure(RetrofitError error) {
LogHelper.debug(error.getMessage);

}
});



what i get from error.getMessage is only the http code status.



if i try to test the api with postman, this will be the response that i capture in JSON format



enter image description here



and this one will be in the raw/plain text format.



enter image description here



This is the client initialize


OkHttpClient mClient = new OkHttpClient().newBuilder().addInterceptor(new PublicApiIntercepter()).build();
return new RestAdapter.Builder()
.setEndpoint(ApplicationConstants.BASE_URL)
.setClient(new Ok3Client(mClient))
.setConverter(new GsonConverter(gson))
.setLogLevel(BuildConfig.DEBUG ? RestAdapter.LogLevel.FULL : RestAdapter.LogLevel.NONE)
.build();



Please help. thank you





What is the value of http code? Check the value of error.getBody().
– Jayson Chacko
Jul 2 at 0:13





@JaysonChacko for error.getMessage == 401 and error.getBody == Method threw 'java.lang.RuntimeException' exception. But if i checked on postman for raw response == "e-mail address not registered"
– thundeNilla
Jul 2 at 0:47




1 Answer
1



Change from :


@POST(ApplicationConstants.USER_URL+"/resendActivationEmail")
void resendEmail(@Body String email, ResponseCallback result);



change to :


@POST(ApplicationConstants.USER_URL+"/resendActivationEmail")
Call<ResponseBody> resendEmail(@Body String email, ResponseCallback result);





I think Call<ResponseBody> only supported in Retrofit2 and its not supported for Retrofit1 @divaP
– thundeNilla
Jul 2 at 5:28







By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to make file upload 'Required' in Contact Form 7?

Rothschild family

amazon EC2 - How to make wp-config.php to writable?