Questions tagged [okhttp]

An HTTP+HTTP/2 client for Android and Java applications.

OkHttp

An HTTP & SPDY client for Android and Java applications. For more information see the website and the wiki.

Overview

HTTP is the way modern applications network. It’s how we exchange data & media. Doing HTTP efficiently makes your stuff load faster and saves bandwidth.

OkHttp is an HTTP client that’s efficient by default:

  • HTTP/2 and SPDY support allows all requests to the same host to share a socket.
  • Connection pooling reduces request latency (if SPDY isn’t available).
  • Transparent GZIP shrinks download sizes.
  • Response caching avoids the network completely for repeat requests.

OkHttp perseveres when the network is troublesome: it will silently recover from common connection problems. If your service has multiple IP addresses OkHttp will attempt alternate addresses if the first connect fails. This is necessary for IPv4+IPv6 and for services hosted in redundant data centers. OkHttp initiates new connections with modern TLS features (SNI, ALPN), and falls back to TLS 1.0 if the handshake fails.

Using OkHttp is easy. Its 2.0 API is designed with fluent builders and immutability. It supports both synchronous blocking calls and async calls with callbacks.

You can try out OkHttp without rewriting your network code. The okhttp-urlconnection module implements the familiar java.net.HttpURLConnection API and the okhttp-apache module implements the Apache HttpClient API.

OkHttp supports Android 2.3 and above. For Java, the minimum requirement is 1.7.

Contributing

If you would like to contribute code you can do so through GitHub by forking the repository and sending a pull request.

When submitting code, please make every effort to follow existing conventions and style in order to keep the code as readable as possible. Please also make sure your code compiles by running mvn clean verify.

Before your code can be accepted into the project you must also sign the Individual Contributor License Agreement (CLA).

4446 questions
2
votes
1 answer

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

java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.NETWORK Hi i got this error while i am calling one API service from retrofit , i am searching a lot and found answer like private static void…
Sushant Gosavi
  • 3,647
  • 3
  • 35
  • 55
2
votes
2 answers

Retrofit change read timeout for one api call

I want to change the read timeout on OkHttp client using retrofit for one api call. To be clear, I have one end point that can take very long, I need to increase it's timeout and only the timeout for that one api call. Is there a way I can do this…
Ali
  • 12,354
  • 9
  • 54
  • 83
2
votes
1 answer

Android httpUrlConnection sending and receiving data

I am aware that here in stackoverflow are plenty of questions related to mine, but I cant understand 100% to their explanations of how to send and receive data from a web server using httpUrlConnection. I used to do it with httpClient and I used the…
Gustavo Serna
  • 117
  • 1
  • 12
2
votes
1 answer

How to do the redirect request based on okhttp3 and retrofit

I am using the okhttp3 and retrofit as the android project request framework, and i have a application scene below: There are two servers in our project with two domain;what we want to do is when connect to one server failed then we reconnect with…
2
votes
1 answer

Retrofit 2: Caching doesn't work after cached response expires

In my android app I'm using retrofit 2 with bundled okhttp. I'm using following code to set the cache OkHttpClient.Builder httpBuilder = new OkHttpClient.Builder(); File httpCacheDirectory = new File(MyApplication.getInstance().getCacheDir(),…
lightsaber
  • 1,481
  • 18
  • 37
2
votes
1 answer

java.lang.NullPointerException using okhttp3 android

I am using okhttp for network requests and responses.I have searched alot on the web and also on github about this issue but i did not get any clean solution, I don't know what is wrong in the code. I am getting NullPointerException when i click on…
Yousaf Iqbal
  • 85
  • 2
  • 10
2
votes
1 answer

Whats the optimal/less-error-prone cache size for OkHttp client (used with exoplayer)

Deps: Kotlin 1.0.3 Exoplayer r1.5.9 Retrofit 2.1.0 okhttp 3.4.1 Im trying to setup cache for my video playback project (list of videos of 20 secs per video) and Im wondering if theres any problem if I set the cache for OkHttp val cacheSize: Long…
Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162
2
votes
1 answer

OkHttp SSLPeerUnverifiedException

I get the following exception with OkHttp 3.3.1 javax.net.ssl.SSLPeerUnverifiedException: Hostname xxx not verified: certificate: xxx DN:xxx subjectAltNames: [] at okhttp3.internal.io.RealConnection.connectTls(RealConnection.java:248) at…
barq
  • 3,681
  • 4
  • 26
  • 39
2
votes
0 answers

Can we use OkHttp lib in Java embedded ME environment?

I like to know if IoT Development Platform of Qualcomm supports OkHttp, which runs in Java Embedded ME. If it does't support Okhttp, kindly suggest any other lib that support Http/2 in Java Embedded ME platform.
qual852
  • 31
  • 5
2
votes
0 answers

How would I send a post request for a google form AM / PM button?

GOOGLE FORM AM/PM OPTION A part of my program's task is to allow the user to enter in the times in the android application, and I have no clue how to do this post request without knowing the ENTRY or form input. I read a bunch of documentation and…
LinearM
  • 133
  • 1
  • 7
2
votes
1 answer

OKHTTP3 POST FORM android application doesn't post anything to Google Forms

I've read and understood the following code from this web page as a reference to developing my android application: https://github.com/square/okhttp/blob/master/samples/guide/src/main/java/okhttp3/recipes/PostForm.java public class PostForm extends…
LinearM
  • 133
  • 1
  • 7
2
votes
0 answers

Google Cloud Storage uploads with OkHttp - streaming vs multipart

I'm using OkHttp to upload files to Google Cloud Storage. Right now, I'm doing a single PUT request with a custom request body and stream the data. The request is something like this: final Request request = new Request.Builder() …
vkislicins
  • 3,331
  • 3
  • 32
  • 62
2
votes
1 answer

Android retrofit send 2d array

I am using retrofit to communicate with a server. I want to send a 2d array which would be like…
Alex Fragotsis
  • 1,248
  • 18
  • 36
2
votes
1 answer

Retrofit Java.lang.IllegalArgumentException host == null

I'm using Retrofit to do some requests to web services, but until recently everything went wrong and I started getting the exception mentioned in the title. I have a base class which basically looks like this: protected BaseService(int version) { …
atanaspl
  • 41
  • 3
2
votes
0 answers

proguard and minifyenabled crash my android app

Build.gradle file: android { compileSdkVersion 23 buildToolsVersion "23.0.2" defaultConfig { applicationId "com.example" minSdkVersion 15 targetSdkVersion 23 versionCode 11 versionName "1" multiDexEnabled true } buildTypes…
Louis B
  • 342
  • 1
  • 5
  • 21
1 2 3
99
100