Questions tagged [okhttp]

1

votes
2

answer
57

Views

How To Know All Asynchronous HTTP Calls are Completed

I am trying to figure out how to determine if all async HTTP GET requests I've made have completed, so that I can execute another method. For context, I have something similar to the code below: public void init() throws IOException { Map mapOfObjects = new HashMap(); ObjectMapper mapper = new Objec...
Pr0pagate
1

votes
1

answer
340

Views

Send file to the server with Retrofit and WebKitFormBoundary in PartMap

I have a query generated by the postman to send files and some info to my server. It works fine in my program. MediaType mediaType = MediaType.parse('multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'); RequestBody body = RequestBody.create(mediaType, '------WebKitFormBoundary7MA4...
Joao
1

votes
2

answer
1.5k

Views

How to close http client connection after getting the response?

I am using http client to send a request. I want to make sure I am closing the connection after the response is received. code: public class WebserviceCall extends AsyncTask { // interface for response AsyncResponse delegate; private final MediaType URLENCODE = MediaType.parse('application/json;char...
Sid
1

votes
0

answer
602

Views

Cannot evaluate com.android.okhttp.HttpUrl$Builder.toString()

The following code seems to cause this exception to be thrown: public static String GET(String url) throws Exception { URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod('GET'); if (con.getResponseCode() == HttpURLConnection.HTTP_OK) {
Or Gat
1

votes
1

answer
420

Views

Upload to pre-signed S3 URL fails with OkHttp

I am getting an SSL exception when I try to upload a file to Amazon S3's pre-signed URL with OkHttp 3.9.1: SSLException: Write error: ssl=0xa0b73280: I/O error during system call, Connection reset by peer It is the same problem as in another SO question but in my case it fails always. I upload just...
shelll
1

votes
1

answer
2.4k

Views

java.io.EOFException: \n not found: limit=0 content=…

I want to connect to webSocket, but an error occurs. How to resolve it? Or it may be error on server side? implementation 'com.squareup.okhttp3:okhttp:3.9.1' Code: final Request request = new Request.Builder() .get() .url('http://develop.by:8000') .build(); OkHttpClient okHttpClient = new OkHttpCli...
NickUnuchek
1

votes
0

answer
851

Views

Create a REST API client for android using Okhttp

I am planning to redesign my REST API client class. I am using Okhttp for making API calls and here is how my current API client class looks like. My API Client class: public class NetworkUtil { private final String API_ENDPOINT_ONE = 'https://api/endpoint/1'; private final String API_ENDPOINT_TWO =...
localhost
1

votes
0

answer
165

Views

Set up a custom trust store that trusts LetsEncrypt in React native

I need to set up a trust store that trusts LetsEncrypt in React native in order to be able to connect to my server which uses Let's encrypt Certificate. This is an example in JAVA (https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/CustomTrust.java) but I don't...
perrosnk
1

votes
0

answer
56

Views

How to detect which timeout timeout occurred?

I have set up OkHTTP in the following way: this.okHttpClient = new OkHttpClient.Builder() .connectTimeout(30, TimeUnit.SECONDS) .writeTimeout(10, TimeUnit.SECONDS) .readTimeout(10, TimeUnit.SECONDS) .build(); And I use the following snippet to send the request try (Response response = this.okHttpCli...
Martin Vseticka
1

votes
1

answer
148

Views

Is it mandatory to include okio if an app wants to use okhttp3?

I have included okhttp3 and tested PATCH and DELETE methods in android versions less than LOLLIPOP (api 21). I did not include Okio and it worked fine. But, in the okhttp site they mention the following: You'll also need Okio, which OkHttp uses for fast I/O and resizable buffers. Download the latest...
garnet
1

votes
0

answer
119

Views

Lots of ReaderRunnable threads still running while doing sync calls

Using OkHttpClient 3.6.0 I have a stream of 100k notifications for the same SSL cert and host to send to APNS. The application reads this stream, queues them and uses an executor service with 800 threads to make a sync call as follows: client.newCall(request).execute() For the past few days, I'm see...
Praveen
1

votes
0

answer
26

Views

app get turn off when i fetch data in arrayadapter through connection

when i click on the this category fragment button in drawer when internet is available the app get close, and if internet connection is not available the it does not stop and shows no data available public class CategoryFragment extends Fragment implements OkHttpInterface { ListView listcategory;...
Soaham saraswat
1

votes
1

answer
212

Views

OkHttp Reverse Http

How to implement reverse http as described in link using OkHttp Currently my implementation is something like Issue is I have to parse http responses which I don't feel safe, its just a coarse implementation, if someone can provide a better alternative String request = 'POST /reverse HTTP/1.1\r\n...
ingsaurabh
1

votes
1

answer
191

Views

NetworkOnMainThreadException while RxJava CompositeDisposable gets disposed

Have another strange issue with RxJava, and I'm guessing it is related to CompositeDisposable.clear causes OkHttp to throw java.lang.IllegalStateException: Unbalanced enter/exit Is it the same issue? The code looks like this: Observable observable = Observable.create(new ObservableOnSubscribe() { @O...
casolorz
1

votes
2

answer
193

Views

OkHttp 504 Gatweway time out error in android

Response{protocol=http/1.1, code=504, message=GATEWAY_TIMEOUT, url=https://************************} I am getting code=504, message=GATEWAY_TIMEOUT in android but the same url got success in iOS OkHttpClient client = new OkHttpClient.Builder() .connectTimeout(30*1000, TimeUnit.MILLISECONDS) .readTi...
shiva
1

votes
1

answer
141

Views

How to get actual User Agent in MFP 8 cordova application(Android/iOS)

Environment Details: 1. CLI version-7.0.0, 2. OKHTTP Version-2.0.0, 3. Cordova-plugin-mfp Version-8.0.2017100610, 4. Cordova-plugin-mfp-push Version-8.0.2017112208, 5. Cordova-Android - ~6.3.0, 6. Cordova-iOS - ^4.4.0 Problem: Android and iPhone Application is built using above version. We have a fi...
Abimanyu
1

votes
0

answer
165

Views

Okhttp big file upload fails

I am experiencing an issue with Okhttp + Node.js Formidable serverside big file upload. Currently the upload works for < 100Mb files but fails for bigger files. For bigger files, the onprogress event serverside is fired until 99% progress, regardless of the file size, then it stops, reports request...
IngvarHorne
1

votes
1

answer
79

Views

OkHttpInterceptor not logging to content to LogCat

I've set OkHttpInterceptor to the OkHttpClient as below: OkHttpClient private static OkHttpClient getOkHttpClient() { OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.addInterceptor(getInterceptor()); builder.authenticator(new TokenAuthenticator()); if (BuildConfig.DEBUG) { builder...
Gokul Nath KP
1

votes
0

answer
50

Views

Trouble with ISO-8859-1 and OkHttp library

I'm writing an app on Java where I use a GET request with the OkHttp library to get some information of a webpage. The webpage is using ISO-8859-1. There is this tag at the top of the page: . The code for the GETrequest is the following: Request request = new Request.Builder() .url(webpage) .get() ....
Mr. Kevin
1

votes
0

answer
816

Views

Retrofit FATAL EXCEPTION: OkHttp Dispatcher, java.lang.NullPointerException: interceptor

App crash always on this point if there is no internet or return null. Following is log FATAL EXCEPTION: OkHttp Dispatcher Process: , PID: 24400 java.lang.NullPointerException: interceptor [email protected] returned null at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain...
Rizwan Ahmed
1

votes
0

answer
586

Views

How to support TLS 1.0 with okhttp in android 4.4 to 5.0

I am using the source code to connect the website with https:// I am using this code: client = new OkHttpClient.Builder().connectTimeout(30, TimeUnit.SECONDS).writeTimeout(3600, TimeUnit.SECONDS).readTimeout(3600, TimeUnit.SECONDS).build(); but it will send back this result: W: javax.net.ssl.SSLHand...
Ata
1

votes
0

answer
249

Views

java.net.UnknownHostException: Unable to resolve host “my_base_server_url”: No address associated with hostname

Often, some users have this exception, and I can't determine how is possible (ie this week 160 users had this problem on 1000 users): java.net.InetAddress.lookupHostByName (InetAddress.java:441) java.net.InetAddress.getAllByName (InetAddress.java:215) okhttp3.Dns$1.lookup (Dns.java:40) okhttp3.inter...
anthony
1

votes
1

answer
230

Views

HTTP requests for real time application, performance tips

I'm using Java's OkHttp3 to send multiple POST requests to the same REST endpoint, which is a third party AWS server on the same region as mine. I need those requests to be processed as fast as possible (even 1ms counts). Right now the only performance tips I'm applying are very basic: I'm using HTT...
Mattx
1

votes
0

answer
9

Views

Want to bypass header match in OkHttp cache

OkHttp3 uses this method in it's cache class to match request and cached responses, my problem is sometimes I don't like to match headers, just URL is fair enough. How can I bypass header matching (comparison) in Cache class? For example maybe I like to accept cached items from previous authenticati...
AVEbrahimi
1

votes
0

answer
205

Views

Unbalanced enter/exit on OkHttp

So I have an exception every so often that says java.lang.IllegalStateException: Unbalanced enter/exit and this happens when the onStop of my activity calls disposables.clear(). I asked about it before and was told it was a D8 bug but I'm on the latest D8 now, or whatever the latest is for Android...
casolorz
1

votes
0

answer
33

Views

Retrofit 2 + interceptors at the level of Call

I'm evaluating Retrofit 2 for our project (Java-based Server Side application with microservices architecture, microservices interact via HTTP) and have a hard time to understand the following: Documentation of OkHttpClient states that instance of OkHttpClient should better be shared for all HTTP Ca...
Mark Bramnik
1

votes
0

answer
104

Views

android OpenSSLSessionImpl finalize SEGV_MAPERR crash

Recently we rewrite our Android application from bottom to up(contains lots of java and native code), maybe change some native library init order; we use OkHttp as our network library. OkHttp version: 3.10.0.1 OkHttpClient OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.connectTim...
linc
1

votes
0

answer
45

Views

How to manage 40MB data in okhttp response body efficiently?

I am getting a 40MB data in the okhttp response. and its taking more than 25 sec responseStr = response.body().string() to process. Can any one help me to reduce the processing time. private String okhttpPost(String xmlRequest) { String responseStr = null; HttpLoggingInterceptor logging = new HttpLo...
Konzern
1

votes
1

answer
18

Views

Does OkHttp support Link rel=preload header?

My team is working on making our REST API more 'hypermedia' by replacing compound documents with links to related resources. We'd obviously like to use HTTP/2 Server Push to make sure it's as fast as possible. However, because of our hosting provider, we are not able to run HTTP/2. It seems like the...
Alan Kušej-Gibson
1

votes
0

answer
361

Views

How to setup fetch for React Native Android using gzip?

My React Native app had been working fine on both iOS and Android but recently it gives Network request failed error on Android when the response is long. I found out if I set the request's header to 'Accept-Encoding': 'gzip',, I was able to log response, but it only contains header and such: { ty...
bleepmeh
1

votes
1

answer
111

Views

Retrofit first request takes exact OkHttpClient timeout

I'm using Retrofit and OkHttpClient to build a Rest API on Android. Some time ago, i had noticed the very first request made by the api always take way longer to process than all others... At begining i didn't care because it was an acceptable time. But suddenly the request time jumped to 60 SECONDS...
Rafael Lima
1

votes
1

answer
171

Views

How can I mock complex (url) API with Retrofit

I need to do something as this website describes: https://blog.davidmedenjak.com/android/2016/11/22/mocking-api-calls.html1 I need to mock my API on certain flavour using some json file, implementing my own OkHttp Interceptor. I'm able todo this with simple url, but how can I do this if the url is m...
Daniele
1

votes
1

answer
25

Views

How to initialize okHttp's MockServer() in a repository?

Server.kt (is a mock server that will return a list of Users) https://github.com/shalbert94/androidinterview/blob/master/server/src/main/java/com/jobrapp/server/Server.kt For some reason, val server = Server() called in my repository (https://github.com/shalbert94/androidinterview/blob/master/app/s...
Shalbert
1

votes
1

answer
241

Views

Retrofit Offline cashing returns a null response.body()

I tried this link and this link to construct an offline Retrofit cache. The problem is that if I put the phone in Airplane mode, the Response.body() is always null. Here's my code: OkHttpClient client = new OkHttpClient .Builder() .cache(new Cache(App.sApp.getCacheDir(), 10 * 1024 * 1024)) // 10 MB...
Mena
1

votes
1

answer
122

Views

OKHTTP newCall() hangs when calling restAPI

Trying to post to a restAPI using JAVA OKHttp. My code looks as follows: try { loggingInterceptor = new HttpLoggingInterceptor(); loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY); client = new OkHttpClient.Builder() .connectTimeout(10, TimeUnit.SECONDS) .addInterceptor(loggingIntercept...
brercia
1

votes
0

answer
37

Views

Invalidate SSLSessions in Android/OkHttp

I need to support potentially using multiple different client certificates against the same host in my app, so in order to do this I assumed the best approach was to invalidate any existing SSLSessions before using another client certificate. However the simplest approach: getting the sessions from...
ASRye
1

votes
0

answer
51

Views

How can I refresh cache after I add,delete or update a data?

Because when I inserted, removed, updated a data, the list of data has not been updated. Please help refresh the cache after modifying a data, so that the display list will also be updated after modifying. My CacheInterceptor: public Response intercept(Chain chain) throws IOException { Response orig...
1

votes
2

answer
30

Views

Does OkHttp have something easier similar to Unirest's field method for creating a RequestBody?

Instead of Unirest, I'm using okhttp because there are responses where I only need the header so I don't need to download it using its ResponseBody.string() method. I am however having a hard time building my requests for POSTs with a RequestBody. In Unirest, you only need to use thefieldmethod to a...
Rigo Sarmiento
1

votes
0

answer
25

Views

Reading HTTP Response When Request Isn't Fully Sent

If I send a large POST request using OkHttp, but the server responds quickly with an error (e.g. permission denied) I get a java.net.SocketException: Broken pipe (Write failed)( status = 272 ) exception. Command line tools like curl seem to handle this case just fine and are able to return the HTTP...
dzelemba
1

votes
0

answer
24

Views

How to track websocket latency in OkHttp3

I am using OkHttp3 to make a websocket connection to a third-party server to receive data. I want to track the latency of the websocket connection. This solution seems the way to go, but without ping/pong being exposed in OkHttp3, how do I figure out the latency?
Rishabh

View additional questions