retrofit

Webservice not working in Android Retrofit , but works in Postman and Swift / iOS, Getting 401 Unauthorized

拜拜、爱过 提交于 2019-12-30 08:33:41
问题 BRIEFING BEFORE 'technical stuff' Not new to working with Retrofit but came across this strange behaviour which I am having very hard time to understand and fix, I have two web service, both work fine as expected in Postman and iOS but only one works in Retrofit and not the other, In my defence I can say I am getting (Unauthorized) response,which means I was able to hit the server and get a result In API developer's defence he says it works in Postman and other devices so not a service issue

Retrofit,onResponse method doesnt work

寵の児 提交于 2019-12-30 07:48:13
问题 Im new in Retrofit,try to get data from one web server,create Model,Interface but this still not working.Problem(maybe) in method onResponse() I add to that method Log.d and Toast but I dont see Log and Toast when launch my app.Why that dont work? I can understand when I get wrong response or something else,but onResponse() dont work in general,how I think.Maybe Toast cant work withoud data,but Log.d must work without it,and Log.d havent data,just code of response. I added all depencies and

RxJava 2 / Retrofit 2 - NetworkOnMainThreadException

空扰寡人 提交于 2019-12-30 06:43:06
问题 I need to perform a request, if my token is expired I need to refresh it and retry the request. This is how I'm trying to do it, at the moment I can refresh the token but it throws me a NetworkOnMainThreadException. It finishes the request,update the token and reaches logs, but that exception its killing me. How can I avoid that? public Observable<Estabelecimento> listarEstabelecimentos() { return Observable.defer(this::getListarEstabelecimentoObservable) .retryWhen(throwableObservable ->

Custom Retrofit ErrorHandler gives UndeclaredThrowableException

谁说胖子不能爱 提交于 2019-12-30 06:25:10
问题 Based on this post How should I handle "No internet connection" with Retrofit on Android I made a custom ErrorHandler private static class CustomErrorHandler implements ErrorHandler { @Override public Throwable handleError(RetrofitError error) { if (error.isNetworkError()) { return new MyNetworkError(); } return error.getCause(); } } And now my application crashes and I get this: java.lang.reflect.UndeclaredThrowableException Is there some configuration needed for the adapter? Using Retrofit

RxJava 的使用入门

六月ゝ 毕业季﹏ 提交于 2019-12-30 05:45:41
一、什么是 RxJava? RxJava 是一个响应式编程框架,采用观察者设计模式。所以自然少不了 Observable 和 Subscriber 这两个东东了。 RxJava 是一个开源项目,地址: https://github.com/ReactiveX/RxJava 还有一个RxAndroid,用于 Android 开发,添加了 Android 用的接口。地址: https://github.com/ReactiveX/RxAndroid 二、例子 通过请求openweathermap 的天气查询接口返回天气数据 1、增加编译依赖 1 dependencies { 2 compile fileTree(dir: 'libs', include: ['*.jar']) 3 compile 'com.android.support:appcompat-v7:22.0.0' 4 compile 'io.reactivex:rxjava:1.0.9' 5 compile 'io.reactivex:rxandroid:0.24.0' 6 compile 'com.squareup.retrofit:retrofit:1.9.0' 7 } retrofit 是一个 restful 请求客户端。详见: http://square.github.io/retrofit/ 2、服务器接口 1

Retrofit with an old school service

烈酒焚心 提交于 2019-12-30 04:06:09
问题 I'm using an external service like : http://domain.com/free/v1/servicename.ext?format=json&num_of_days=4 I try to use Retrofit like that : @GET("/free/v1/servicename.ext?format=json&num_of_days={numOfDays}") void serviceName(@Path("numOfDays") int numOfDays, Callback<Result> callback); but an exception is thrown : URL query string must not have replace block. Is it compatible with this kind of url ? 回答1: It absolutely is compatible with it! You can't use @Path inside of the query parameters.

Retrofit 2/OkHttp: Cancel all running requests

扶醉桌前 提交于 2019-12-30 02:08:12
问题 I'm using Retrofit 2-beta2 with OkHttp 2.7.0. To get the OkHttpClient object from Retrofit I'm using the Retrofit .client() method and to cancel all it's running requests, I'm calling it's cancel(Object tag) method but the requests still keep running and I get a response. Even the client's Dispatcher 's getQueuedCallCount() and getRunningCallCount() return 0 after calling cancel(). Is there anything else that I need to do for this to work? Or could it be a bug in OkHttp? As a workaround, I'm

retrofit 2.0 how to print the full json response?

◇◆丶佛笑我妖孽 提交于 2019-12-30 01:34:05
问题 I am moving from Volley to Retrofit currently version 2.0. How to print the the full json response code ? includes : compile 'com.squareup.retrofit:converter-gson:2.0.0-beta2' compile 'com.squareup.retrofit:retrofit:2.0.0-beta2' RestClient : OkHttpClient client = new OkHttpClient(); client.interceptors().add(new Interceptor() { @Override public Response intercept(Interceptor.Chain chain) throws IOException { Response response = chain.proceed(chain.request()); return response; } }); Gson gson

Getting JSON from RetrofitError object using Retrofit

我是研究僧i 提交于 2019-12-29 18:44:11
问题 I am using the Retrofit library to do REST calls to a service I am using. If I make an API call to my service and have a failure, the service returns a bit of JSON along with the standard HTTP error stuff. Using the RetrofitError object included in the failure callback I am able to find the HTTP status code and several other things, however I am not able to retrieve the JSON that the service sends back. For example, let's say I make a call to the API where I am trying to create a user. If the

Retrofit - @Body parameters cannot be used with form or multi-part encoding

余生颓废 提交于 2019-12-29 18:17:21
问题 I m trying to make a request in which I want to include a Header , a form-urlencoded field and a json body. My Retrofit interface is as follows @FormUrlEncoded @POST("/api/register") Observable<RegisterResponse> register( @Header("Authorization") String authorization, @Field("grant_type") String grantType, @Body RegisterBody body ); When I make this request I get back exception @Body parameters cannot be used with form or multi-part encoding. I have also tried with the @Multipart annotation: