Questions tagged [okhttp]

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
1

votes
0

answer
20

Views

Authenticate from Authenticator Okhttp3 has 200 response code but it keeps calling til message Too many follow-up requests: 21

I'm using ADFS server... In Authenticator (authenticate), constantly getting Response{protocol=http/1.1, code=200, message=OK, url=XXX} but at the end onFailure: Too many follow-up requests: 21. Retrofit 2.3.0
user2974669
1

votes
1

answer
267

Views

Onedrive api to upload file

I went through many references(including onedrive api doc) but i'm unable to upload a file into onedrive using okhttp request. The following is the code that I tried: try { boolean status; String url = String.format('onedrive.live.com/v1.0/drive/root:/'+step.file_name+':/content'); //exceptions ar...
K.venkatesh
1

votes
1

answer
40

Views

How to save result from a GET request with OkHttp in a local variable?

I'm trying to make a Get Request with OkHttp in Java. I made it successfully using asynchronous threads but I'm 'stuck' Inside onResponse function. I mean, I can't use the result of the request anywhere else than in this function. How can I do to make this code work ? OkHttpClient client = new OkHtt...
Mathieu Gasciolli
1

votes
2

answer
35

Views

Crash when OkHttp requests incorrect links

When I asked for a link using OKHttp, it crashed because it wasn't the right link, how do I capture the crash, and I'm not sure if there will be any of these wrong links in the future. I need to capture him to avoid program crashes this article is generated through translation tools, if you don't u...
陈志坚
1

votes
0

answer
26

Views

Building an android client application to interact with a streaming service that supports HTTP2

I am building an android application that will interact with a streaming service. The service supports http2 connections. Application will send chunks of audio files(Chunked from live audio input through a microphone or chunked from a large audio file) over the wire. The service will return text tra...
Roshan
1

votes
0

answer
173

Views

OkHttp is using reflection, which violates Android 9 limitations on non-SDK methods?

In Android 9 Google announced new limitations on accessing non-SDK interface methods by using reflection. If your project uses one, you will get the dialog Detected problems with API compatibility (visit g.co/dev/appcompat for more info). Although as far as I know this dialog will not appear in a re...
Sira Lam
1

votes
1

answer
39

Views

Efficient okio Source backed by an already allocated ByteString?

When using the OkHttp Websocket the listener uses a ByteString to provide the binary payload to the application. I want to feed these bytes into some code which takes a okio.Source (in this particular case, a GzipSource), but I cannot find any good way to do this efficiently. My current solution lo...
Johan Ström
1

votes
3

answer
40

Views

Get Weather status of multiple locations inside for loop android

I am developing a weather app for that I am using dark sky API in which I want to know the weather status of a bunch of locations which I have stored in ArrayList. I am using OKHttp to parse the JSON data from API, so I tried to loop the whole fetching process inside for loop but it doesn't give the...
Adarsh
1

votes
1

answer
30

Views

Okhttp3 with consrypt for http2 support in jdk8

I've been testing around okhttp3 for making http2 requests, my criteria is to achieve http2 connection using jdk8 itself. I knew this can be easily achieved by upgrading to jdk 9 or using conscrypt as default provider like, Security.insertProviderAt(Conscrypt.newProvider(), 1); But inserting the pr...
Zyber
1

votes
0

answer
31

Views

How to fix SSL Handshake Error when device is connected to the network but not logged in through website to access Internet?

On opening the Application when the device is connected to the network but not logged in to the network through web portal to access internet, My Code is having trouble with adding interceptor. operator fun invoke(prefManager: PrefManager): ApiServices { val loggingInterceptor = HttpLoggingIntercep...
Rubin Bajracharya
1

votes
2

answer
21

Views

Send Data from SQLite to appServer using POST,OKHttp

I have an SQLite Db which stores call logs. Each entry has a number, date, and duration. I have seen that there are many ways we can send the data to the app server. As a JSON String and send one by one from an ArrayList of model class objects. Which is the correct way to approach this? And how can...
Lenzman
1

votes
0

answer
18

Views

Can't Upload the file in Retrofit2.0?

am Using Retrofit2.0 not able to upload the file from java. It gives response as Code as 415. RetofitCode File uploadFile1 = new File('/home/art-pc-mob-001/MISSTorewise.png'); Retrofit retrofit = new Retrofit.Builder().baseUrl(endPointURL + 'v1/') .addConverterFactory(GsonConverterFactory.create())....
Yugesh

View additional questions