okhttp3

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

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(

How to send post parameters dynamically (or in loop) in OKHTTP 3.x in android?

拟墨画扇 提交于 2019-11-30 14:38:08
问题 I am using OKHTTP 3.x version. I want to post multiple parameters and would like to add the params in a loop. I know that in version 2.x , I can use FormEncodingBuilder and add params to it in loop and then from it create a request body. But In 3.x , the class has been removed. Here is my current code : RequestBody formBody = new FormBody.Builder() .add("Param1", value1) .add("Param2", value2) .build(); Request request = new Request.Builder() .url("url") .post(formBody) .build(); Now I want

How to send post parameters dynamically (or in loop) in OKHTTP 3.x in android?

五迷三道 提交于 2019-11-30 11:08:43
I am using OKHTTP 3.x version. I want to post multiple parameters and would like to add the params in a loop. I know that in version 2.x , I can use FormEncodingBuilder and add params to it in loop and then from it create a request body. But In 3.x , the class has been removed. Here is my current code : RequestBody formBody = new FormBody.Builder() .add("Param1", value1) .add("Param2", value2) .build(); Request request = new Request.Builder() .url("url") .post(formBody) .build(); Now I want to add 5 params but in a loop i.e create request body by building formbody in a loop. Like I wrote above

Connection pool and File handles

情到浓时终转凉″ 提交于 2019-11-30 10:11:53
We use Retrofit/OkHttp3 for all network traffic from our Android application. So far everything seems to run quite smoothly. However, we have now occasionally had our app/process run out of file handles. Android allows for a max of 1024 file handles per process OkHttp will create a new thread for each async call Each thread created this way will (from our observation) be responsible for 3 new file handles (2 pipes and one socket). We were able to debug this exactly, where each dispached async call using .enqueue() will lead to an increase of open file handles of 3. The problem is, that the

How can I make a simple HTTP request in MainActivity.java? (Android Studio)

与世无争的帅哥 提交于 2019-11-30 09:41:24
I'm using Android Studio, and I've spent a few hours trying to do a simple HTTP request in my MainActivity.java file, and tried multiple ways, and seen many web pages on the subject, yet cannot figure it out. When I try OkHttp, I get a error about not being able to do it on the main thread. Now I'm trying to do it this way: public static String getUrlContent(String sUrl) throws Exception { URL url = new URL(sUrl); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setDoOutput(true); connection.setConnectTimeout(5000);

OkHttpClient cannot cancel Call by tag

一曲冷凌霜 提交于 2019-11-30 08:44:08
问题 I recently upgraded to OkHttp3, and noticed that you could no longer cancel a Call by tag directly from the Client. This has to be handled by the application now. Stated in the CHANGELOG here: Canceling batches of calls is now the application's responsibility. The API to cancel calls by tag has been removed and replaced with a more general mechanism. The dispatcher now exposes all in-flight calls via its runningCalls() and queuedCalls() methods. You can write code that selects calls by tag,

GET request with request body in OkHttp

Deadly 提交于 2019-11-30 05:11:43
问题 I'm trying to use OkHttp 3.6.0 with Elasticsearch and I'm stuck with sending requests to the Elasticsearch Multi GET API. It requires sending an HTTP GET request with a request body. Unfortunately OkHttp doesn't support this out of the box and throws an exception if I try to build the request myself. RequestBody body = RequestBody.create("text/plain", "test"); // No RequestBody supported Request request = new Request.Builder() .url("http://example.com") .get() .build(); // Throws: java.lang

Android java.security.cert.CertPathValidatorException: Trust anchor for certification path not found

ぐ巨炮叔叔 提交于 2019-11-30 05:06:41
There are three hosts that an android app do the authentication and authorization. Final host is the REST API. For the first time using Oauth authentication and authorization process it works without issue. But if user kills the app after login and accessing the services provided by REST API and then again open the app, this issue arise. In this time authentication and authorization process is not happening, only the REST API. It caused to java.security.cert.CertPathValidatorException but it was working during the first use (login and then use the app). Can someone explains the scenario behind