Reputation: 163
I'm getting a null response when i call API with city with spaces: for example "San Francisco". When for example "Mexico" is working fine.
i've tried replacing spaces with "+", but it' doesn't work in android. But in postman it worked.
here's call code:
Api api = ApiBuilder.createApi();
Call<CurrentWeather> currentWeatherCall =
api.getCurrentWeather(API_KEY, "san+francisco", UNITS);
currentWeatherCall.enqueue(new Callback<CurrentWeather>() {
@Override
public void onResponse(Call<CurrentWeather> call,
Response<CurrentWeather> response) {
try {
Toast.makeText(getApplicationContext(), response.body().getCityName(),
Toast.LENGTH_SHORT).show();
}
Upvotes: 0
Views: 70
Reputation: 584
if you use logging-interceptor
then you can see response from the server in Verbose Log.
in Gradle
implementation 'com.squareup.okhttp3:logging-interceptor:3.5.0'
in Interface
public static PostService postService = null;
public static PostService getService() {
if (postService == null) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(base_url)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.build();
postService = retrofit.create(PostService.class);
}
return postService;
}
if api call is made then server response can be seen in Verbose then you debug
Upvotes: 1