retrofit2

RxJava 2 / Retrofit 2 - NetworkOnMainThreadException

随声附和 提交于 2019-11-30 22:00:41
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 -> throwableObservable.flatMap( throwable -> { if (throwable instanceof UnauthorizedException) { return

Android with Retrofit2 OkHttp3 - Multipart POST Error

一曲冷凌霜 提交于 2019-11-30 21:53:58
I am using Retrofit2 with OkHttp on Android for HTTP request. Here I am doing a POST request with document upload. I ran into error below: D/OkHttp: <-- 500 Server Error http://api.drivewealth.io/v1/documents (4289ms) D/OkHttp: Date: Tue, 11 Apr 2017 03:29:48 GMT D/OkHttp: Cache-Control: must-revalidate,no-cache,no-store D/OkHttp: Content-Type: text/html; charset=ISO-8859-1 D/OkHttp: Server: Jetty(9.2.17.v20160517) D/OkHttp: Content-Length: 9323 D/OkHttp: Connection: keep-alive D/OkHttp: <html> D/OkHttp: <head> D/OkHttp: <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/> D

How to handle network errors in Retrofit 2 with RxJava

南笙酒味 提交于 2019-11-30 19:30:18
问题 I am using Retrofit2 with RxJava. So my call looks something like subscriptions.add(authenticateUser(mReq, refreshRequest) .observeOn(Schedulers.io()) .subscribeOn(Schedulers.io()) .subscribe(authResponseModel -> { processResponse(authResponseModel, userName, encryptedPass); }, throwable -> { LOGW(TAG, throwable.getMessage()); })); It's an authentication api. So when the api call fails, I get a response from the server like {"messages":["Invalid username or password "]} along with 400 Bad

Retrofit 2: responseBodyConverter converts to null object

99封情书 提交于 2019-11-30 18:51:51
I'm using the latest (as of now 2.0.0-beta4) version of Retrofit . When receiving 200 OK code from server, everything is working fine. But I want to deal with not OK responses too, such as code 401. So, I have to get the error response code to figure out exactly what action to do and display appropriate data: @Override public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) { if (response != null && !response.isSuccess() && response.errorBody() != null) { Converter<ResponseBody, APIError> errorConverter = retrofit.responseBodyConverter(APIError.class, new Annotation

Android with Retrofit2 OkHttp3 - Multipart POST Error

…衆ロ難τιáo~ 提交于 2019-11-30 17:59:16
问题 I am using Retrofit2 with OkHttp on Android for HTTP request. Here I am doing a POST request with document upload. I ran into error below: D/OkHttp: <-- 500 Server Error http://api.drivewealth.io/v1/documents (4289ms) D/OkHttp: Date: Tue, 11 Apr 2017 03:29:48 GMT D/OkHttp: Cache-Control: must-revalidate,no-cache,no-store D/OkHttp: Content-Type: text/html; charset=ISO-8859-1 D/OkHttp: Server: Jetty(9.2.17.v20160517) D/OkHttp: Content-Length: 9323 D/OkHttp: Connection: keep-alive D/OkHttp:

Retrofit API call receives “HTTP FAILED: java.io.IOException: Canceled”

爷,独闯天下 提交于 2019-11-30 17:05:08
Can't figure out why is this happening. Neither one of rx callbacks (onCompleted(), onError(), onNext()) not gets triggered by my call. The only thing i receive is this okhttp output: D/OkHttp: --> GET https://api.privatbank.ua/p24api/exchange_rates?json=true&date=20.11.2016 http/1.1 D/OkHttp: --> END GET D/OkHttp: <-- HTTP FAILED: java.io.IOException: Canceled Retrofit module: @Module public class RestModule { @Provides @Singleton public HttpLoggingInterceptor providesHttpLogginInterceptor() { return new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY); } @Provides

Retrofit: how to parse GZIP'd response without Content-Encoding: gzip header

 ̄綄美尐妖づ 提交于 2019-11-30 15:40:27
问题 I'm trying to process a server response which is GZIP'd. The response comes with a header Content-Type: application/x-gzip but does not have header Content-Encoding: gzip If I add that header using a proxy, the response gets parsed just fine. I don't have any control over the server, so I can't add the header. Can I force Retrofit to treat it as GZIP content? Is there a better way? The URL for the server is: http://crowdtorch.cms.s3.amazonaws.com/4474/Updates/update-1.xml 回答1: There is a

Get html of a website with retrofit - Android?

烈酒焚心 提交于 2019-11-30 15:07:18
How can I get html of a website with retrofit ? for example I have this url and I need to get html of this url and how can I load more . Bellow is my code : MainActivity.java: public class MainActivity extends AppCompatActivity { TextView txt; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt = (TextView) findViewById(R.id.txt); OkHttpClient okHttpClient = new OkHttpClient().newBuilder() .build(); Retrofit retrofit = new Retrofit.Builder() .baseUrl("https://www.instagram.com/elde0596/")

Retrofit: how to parse GZIP'd response without Content-Encoding: gzip header

安稳与你 提交于 2019-11-30 15:01:27
I'm trying to process a server response which is GZIP'd. The response comes with a header Content-Type: application/x-gzip but does not have header Content-Encoding: gzip If I add that header using a proxy, the response gets parsed just fine. I don't have any control over the server, so I can't add the header. Can I force Retrofit to treat it as GZIP content? Is there a better way? The URL for the server is: http://crowdtorch.cms.s3.amazonaws.com/4474/Updates/update-1.xml There is a better way than reinventing the wheel. Just add the Content-Encoding header yourself. .addNetworkInterceptor(

Retrofit not working on specific versions of android

橙三吉。 提交于 2019-11-30 14:11:15
I have a problem with Retrofit on my emulator running Android 4.3 and my device is on Android 4.4.2 while the same code runs normally on another emulator with Android 7.1.1 Each time I try to execute the get request I get a timeout exception. java.net.SocketTimeoutException: failed to connect to jsonplaceholder.typicode.com/2606:4700:30::681c:3f5 (port 443) after 10000ms at libcore.io.IoBridge.connectErrno(IoBridge.java:159) at libcore.io.IoBridge.connect(IoBridge.java:112) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:192) at java.net.PlainSocketImpl.connect(PlainSocketImpl.java