okhttp | Square ’ s meticulous HTTP client for the JVM Android | HTTP library

 by   square Kotlin Version: 4.11.0-patch-1 License: Apache-2.0

kandi X-RAY | okhttp Summary

kandi X-RAY | okhttp Summary

okhttp is a Kotlin library typically used in Networking, HTTP applications. okhttp has a Permissive License and it has high support. However okhttp has 29 bugs and it has 31 vulnerabilities. You can download it from GitHub.

See the [project website][okhttp] for documentation and APIs. 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.

            kandi-support Support

              okhttp has a highly active ecosystem.
              It has 44108 star(s) with 9123 fork(s). There are 1637 watchers for this library.
              There were 1 major release(s) in the last 12 months.
              There are 72 open issues and 3758 have been closed. On average issues are closed in 363 days. There are 14 open pull requests and 0 closed requests.
              It has a positive sentiment in the developer community.
              The latest version of okhttp is 4.11.0-patch-1

            kandi-Quality Quality

              okhttp has 29 bugs (3 blocker, 1 critical, 18 major, 7 minor) and 1664 code smells.

            kandi-Security Security

              okhttp has 2 vulnerability issues reported (0 critical, 0 high, 2 medium, 0 low).
              okhttp code analysis shows 29 unresolved vulnerabilities (0 blocker, 29 critical, 0 major, 0 minor).
              There are 169 security hotspots that need review.

            kandi-License License

              okhttp is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              okhttp releases are not available. You will need to build from source code and install.
              Installation instructions are not available. Examples and code snippets are available.
              okhttp saves you 68929 person hours of effort in developing the same functionality from scratch.
              It has 86296 lines of code, 6519 functions and 530 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed okhttp and discovered the below as its top functions. This is intended to give you an instant insight into okhttp implemented functionality, and help decide if they suit your requirements.
            • Fetches a http request .
            • Dispatch the request to Slack
            • Stream the primes asynchronously .
            • Create a SSL context from a keystore file .
            • Exchange an OAuth token .
            • Requests an OAuth login URL .
            • Closes the WebSocket .
            • Run the test
            • Returns the default trust manager .
            • Creates a JSON string that will be displayed as a string .
            Get all kandi verified functions for this library.

            okhttp Key Features

            No Key Features are available at this moment for okhttp.

            okhttp Examples and Code Snippets

            The OkHttp client .
            javadot img1Lines of Code : 4dot img1License : Permissive (MIT License)
            copy iconCopy
                public OkHttpClient client() {
                    return new OkHttpClient();
            Mock beans created inside Configuration class - Spring Boot with JUnit 5
            Lines of Code : 36dot img2License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            public class TestConfig {
              public static MockWebServer mockWebServer = new MockWebServer();
              @Bean(name = "client")
              private static WebClient getWC1(){
                return WebClient.builder().baseUrl("http://localhost:" + mockWeb
            copy iconCopy
            private val logger = Logger.getLogger(MockWebServer::class.java.name)
            fun  T.setPrivateProperty(variableName: String, data: Any): Any? {
                return javaClass.getDeclaredField(variableName).let { field ->
            Spring boot : How to write unit test case for delete rest template
            Javadot img4Lines of Code : 51dot img4License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            public class HttpHandlerTest {
                private final HttpHandler handler = new HttpHandler();
                public void testDelete() {
                    MockWebServer mockWebServer = new MockWebServer();
            copy iconCopy
             val mockWebServer = MockWebServer().apply {
                    val localhost: String = InetAddress.getByName("localhost").canonicalHostName
                    val localhostCertificate: HeldCertificate = HeldCertificate.Builder().addSubjectAlternativeName(local
            Unit Testing POST request body while using WebClient
            Javadot img6Lines of Code : 4dot img6License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            MockWebServer server = new MockWebServer();
            RecordedRequest request = server.takeRequest();
            assertEquals("{}", request.getBody().readUtf8());
            Mocking a http response using vert.x rxjava2 and Mockito
            Lines of Code : 52dot img7License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                public class WebServiceTest {
                    private WebServiceRequester sut;
                    private MockWebServer mockWebServer;
                    public void setUp() {
                        sut =
            write unit test case for this method returning RxJava Future
            Javadot img8Lines of Code : 55dot img8License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            import okhttp3.mockwebserver.MockResponse;
            import okhttp3.mockwebserver.MockWebServer;
            import okhttp3.mockwebserver.RecordedRequest;
            // other imports omitted
            public class VendorDetailsTest {
            How to write Junit test case for postAbs method of WebClient in Vert.x?
            Lines of Code : 52dot img9License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
                public class ServiceExecutionHelperTest {
                    private ServiceExecutionHelper sut;
                    private MockWebServer mockWebServer;
                    public void setUp() {
            How to mock this webClient using JUnit?
            Javadot img10Lines of Code : 53dot img10License : Strong Copyleft (CC BY-SA 4.0)
            copy iconCopy
            class ApiCaller {
                private WebClient webClient;
                ApiCaller(WebClient webClient) {
                     this.webClient = webClient;
                Mono callApi() {
                     return webClient.put()

            Community Discussions


            Crashing when first time try OkHttp as a client
            Asked 2022-Apr-02 at 04:40

            I'm have some project, realtime sending RSSI and MAC of Bluetooth Low Energy. I want try using http protocol, and i found OkHttp library. But when i run with OkHttp, my software crash.

            My error



            Answered 2022-Apr-02 at 04:40

            The error is caused due to execution of network request on main thread (a.k.a. UI thread). In general, thread blocking operations (like file read, network requests) are prohibited on main thread. This is done to avoid App Not responding error.

            In your mainActivity.java, since BroadcastReceiver#onReceive is executed on main thread. (Ref: https://stackoverflow.com/a/5676888/5309486 ). And inside this onReceive function, you are trying to make the network request.

            Just, use handler and post the network call to background thread (or any other thread) and that will fix your issue.

            Source https://stackoverflow.com/questions/71714648


            Retrofit OkHttp - "unexpected end of stream"
            Asked 2022-Mar-27 at 18:38

            I am getting "Unexpected end of stream" while using Retrofit (2.9.0) with OkHttp3 (4.9.1)

            Retrofit configuration:



            Answered 2022-Mar-27 at 18:38

            OK, It took some time, but I've found what was going wrong and how to workaround that.

            When Android Studio's emulators running in Windows series OS (checked for 7 & 10) receive json-typed reply from server with retrofit it can with various probability loose 1 or 2 last symbols of the body when it is decoded to string, this symbols contain closing curly brackets and so such body could not be parsed to object by gson converter which results in throwing exception.

            The idea of workaround I found is to add an interceptor to retrofit which would check the decoded to string body if its last symbols match those of valid json response and add them if they are missed.

            Source https://stackoverflow.com/questions/70246508


            OkHttpClient sometimes getting incomplete json response
            Asked 2022-Mar-03 at 12:02

            I have been facing this incomplete json error and unable to find the issue. The API response work fine in POSTMAN. But this issue happened in my android emulator and it only happened randomly. This project is build with kotlin dagger-hilt retrofit2 okhttp3 gson.

            Success Response



            Answered 2022-Mar-03 at 12:02

            I suspect the Android emulator might be interfering with you here. I’ve seen issues with it misbehaving, particularly on Windows.


            If you'd like to workaround, consider changing your server to use something other than Connection: close to terminate your response body. Perhaps chunked encoding or a content-length header.

            Source https://stackoverflow.com/questions/71333263


            Specify Content-Type in form-data part as application/json
            Asked 2022-Feb-25 at 12:24

            I am creating a multipart RequestBody using OkHttp3. The following is the working curl request.



            Answered 2022-Feb-25 at 05:35

            After playing with this code, I got a way to specify the Content-Type.

            Source https://stackoverflow.com/questions/71261294


            android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify
            Asked 2022-Feb-23 at 14:13

            After upgrading to android 12, the application is not compiling. It shows

            "Manifest merger failed with multiple errors, see logs"

            Error showing in Merged manifest:

            Merging Errors: Error: android:exported needs to be explicitly specified for . Apps targeting Android 12 and higher are required to specify an explicit value for android:exported when the corresponding component has an intent filter defined. See https://developer.android.com/guide/topics/manifest/activity-element#exported for details. main manifest (this file)

            I have set all the activity with android:exported="false". But it is still showing this issue.

            My manifest file:



            Answered 2021-Aug-04 at 09:18

            I'm not sure what you're using to code, but in order to set it in Android Studio, open the manifest of your project and under the "activity" section, put android:exported="true"(or false if that is what you prefer). I have attached an example.

            Source https://stackoverflow.com/questions/68554294


            minio Unsupported OkHttp library found. Must use okhttp >= 4.8.1
            Asked 2022-Feb-09 at 21:28

            after using minio as instructions and fixing it with ways below, I failed.what can i do to solve this bug



            Answered 2022-Feb-09 at 21:28

            I also experienced this issues with io.minio:minio:8.3.6, but was able to force a newer version of okhttp, which works with the MinIO client library. Here is the snippet of build.gradle (should work similar with Maven):

            Source https://stackoverflow.com/questions/70914692


            NoSuchMethodError on com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()
            Asked 2022-Feb-09 at 12:31

            I'm parsing a XML string to convert it to a JsonNode in Scala using a XmlMapper from the Jackson library. I code on a Databricks notebook, so compilation is done on a cloud cluster. When compiling my code I got this error java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()Lcom/fasterxml/jackson/databind/cfg/MutableCoercionConfig; with a hundred lines of "at com.databricks. ..."

            I maybe forget to import something but for me this is ok (tell me if I'm wrong) :



            Answered 2021-Oct-07 at 12:08

            Welcome to dependency hell and breaking changes in libraries.

            This usually happens, when various lib bring in different version of same lib. In this case it is Jackson. java.lang.NoSuchMethodError: com.fasterxml.jackson.dataformat.xml.XmlMapper.coercionConfigDefaults()Lcom/fasterxml/jackson/databind/cfg/MutableCoercionConfig; means: One lib probably require Jackson version, which has this method, but on class path is version, which does not yet have this funcion or got removed bcs was deprecated or renamed.

            In case like this is good to print dependency tree and check version of Jackson required in libs. And if possible use newer versions of requid libs.

            Solution: use libs, which use compatible versions of Jackson lib. No other shortcut possible.

            Source https://stackoverflow.com/questions/69480470


            RN Release build fails, but debug runs. Error:Execution failed for task ':app:compileReleaseJavaWithJavac'
            Asked 2022-Feb-07 at 03:56

            I have a react-native app that runs perfectly well in debug, but fails on a release build. Running node 16.3.2 inside Windows 11 with react-native 0.63.4

            Any thoughts on what to try would be greatly appreciated.

            The build error from gradlew assembleRelease is:



            Answered 2022-Feb-07 at 03:56

            Try declaring the package separately above the imports like this:

            Source https://stackoverflow.com/questions/71013290


            Issue with okhttp and minio 3.x packages
            Asked 2022-Jan-20 at 05:38

            I have a Java 8 project using Maven to import io.minio minio package. We have been using minio package 8.2.1 but due to this vulnerability we are trying to update this package to a newer version. After trying to update to any of the 8.3 versions, I get the following stacktrace while trying to construct a new MinioClient object:



            Answered 2022-Jan-20 at 05:38

            Your build tool should be pulling in OkHttp’s transitive dependencies, Okio and Kotlin-stdlib. It appears from this stacktrace that the Kotlin stdlib is either outdated or absent? Update that and this crash should be fixed.

            Source https://stackoverflow.com/questions/70777182


            How can I get the number of actual bytes transferred with OkHttp3?
            Asked 2022-Jan-19 at 22:04

            OkHttp does a great job of transparently handling GZIP content encoding. When I call response.body().contentLength() I get the decoded size of the response.

            How can I get the number of bytes actually transferred in the HTTP response?

            Alternately, getting the value from the original Content-Length header would do.

            I am trying to keep track of how many bytes I have downloaded over a metered connection.



            Answered 2022-Jan-19 at 22:04

            Look at EventListener, which tracks bytes transmitted over the network.


            Source https://stackoverflow.com/questions/70773894

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            ** DISPUTED ** CertificatePinner.java in OkHttp 3.x through 3.12.0 allows man-in-the-middle attackers to bypass certificate pinning by changing SSLContext and the boolean values while hooking the application. NOTE: This id is disputed because some parties don't consider this is a vulnerability. Their rationale can be found in https://github.com/square/okhttp/issues/4967.

            Install okhttp

            You can download it from GitHub.


            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone square/okhttp

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link