When I use postman to communicate with the endpoint it's work fine but with Retrofit2 I get 406 Not Acceptable
message as shown in the LogCat. I found some related questions in SO I tried the accepted answer solution (add the content type in the header) but doesn't work for me
Retrofit Config
public interface AndroidAppService {
....
@Headers({
"Content-Type: text/html; charset=UTF-8" // I also tried application/json
}) @GET("subscribers/{msisdn}/verify") Observable<HeaderResponse> checkPhoneNumber(
@Path("msisdn") String phoneNumber);
....
class Factory {
public static AndroidAppService create(String baseUrl) {
HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.HEADERS);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();
Retrofit retrofit = new Retrofit.Builder().baseUrl(baseUrl)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit.create(AndroidAppService.class);
}
}
}
LogCat
08-13 18:59:02.376 17766-22236/com.androidapp D/OkHttp: --> GET http://androidapp.net/bo/web/app_dev.php/api/subscribers/0827873/verify http/1.1
08-13 18:59:02.376 17766-22236/com.androidapp D/OkHttp: --> END GET
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: <-- 406 Not Acceptable http://com.androidapp.com
/bo/web/app_dev.php/api/subscribers/072736263/verify (10680ms)
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: Date: Sat, 13 Aug 2016 18:58:07 GMT
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: Server: Apache/2.4.7 (Ubuntu)
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: X-Powered-By: PHP/5.5.9-1ubuntu4.14
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: Cache-Control: no-cache
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: X-Debug-Token: d28d0a
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: X-Debug-Token-Link: http://com.androidapp/bo/web/app_dev.php/_profiler/d28d0a
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: Keep-Alive: timeout=5, max=100
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: Connection: Keep-Alive
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: Transfer-Encoding: chunked
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: Content-Type: text/html; charset=UTF-8
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: OkHttp-Sent-Millis: 1471113729149
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: OkHttp-Received-Millis: 1471113729517
08-13 18:42:09.512 6350-6927/com.androidapp D/OkHttp: <-- END HTTP