square/okhttp là dự án Mobile trên GitHub, viết chủ yếu bằng Kotlin, với 47.1k sao. A meticulous HTTP client for the JVM, Android, and GraalVM.
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
See the project website 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.
OkHttp is an HTTP client that’s efficient by default:
HTTP/2 support allows all requests to the same host to share a socket.
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 services hosted in redundant data
centers. OkHttp supports modern TLS features (TLS 1.3, ALPN, certificate pinning). It can be
configured to fall back for broad connectivity.
Using OkHttp is easy. Its request/response API is designed with fluent builders and immutability. It
supports both synchronous blocking calls and async calls with callbacks.
A well behaved user agent
OkHttp follows modern HTTP specifications such as
HTTP Semantics - RFC 9110
HTTP Caching- RFC 9111
HTTP/1.1 - RFC 9112
HTTP/2 - RFC 9113
Websockets - RFC 6455
SSE - Server-sent events
Where the spec is ambiguous, OkHttp follows modern user agents such as popular Browsers or common HTTP Libraries.
OkHttp is principled and avoids being overly configurable, especially when such configuration is
to workaround a buggy server, test invalid scenarios or that contradict the relevant RFC.
Other HTTP libraries exist that fill that gap allowing extensive customisation including potentially
invalid requests.
Example Limitations
Does not allow GET with a body.
Cache is not an interface with alternative implementations.
Get a URL
This program downloads a URL and prints its contents as a string. Full source.
This program posts data to a service. Full source.
public static final MediaType JSON = MediaType.get("application/json");
OkHttpClient client = new OkHttpClient();
String post(String url, String json) throws IOException {
RequestBody body = RequestBody.create(json, JSON);
Request request = new Request.Builder()
.url(url)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
return response.body().string();
}
}
Further examples are on the OkHttp Recipes page.
Requirements
OkHttp works on Android 5.0+ (API level 21+) and Java 8+.
On Android, OkHttp uses AndroidX Startup. If you disable the initializer in the manifest,
then apps are responsible for calling OkHttp.initialize(applicationContext) in Application.onCreate.
OkHttp depends on Okio for high-performance I/O and the Kotlin standard library. Both are small libraries with strong backward-compatibility.
We highly recommend you keep OkHttp up-to-date. As with auto-updating web browsers, staying current
with HTTPS clients is an important defense against potential security problems. We
track the dynamic TLS ecosystem and adjust OkHttp to improve connectivity and
security.
OkHttp uses your platform's built-in TLS implementation. On Java platforms OkHttp also supports
Conscrypt, which integrates BoringSSL with Java. OkHttp will use Conscrypt if it is
the first security provider:
Snapshot builds are available. R8 and ProGuard rules are available.
Also, we have a bill of materials (BOM) available to help you keep OkHttp artifacts up to date and be sure about version compatibility.
dependencies {
// define a BOM and its version
implementation(platform("com.squareup.okhttp3:okhttp-bom:5.5.0"))
// define any required OkHttp artifacts without version
implementation("com.squareup.okhttp3:okhttp")
implementation("com.squareup.okhttp3:logging-interceptor")
}
Maven and JVM Projects
OkHttp is published as a Kotlin Multiplatform project. While Gradle handles this automatically,
Maven projects must select between okhttp-jvm and okhttp-android. The okhttp artifact will be empty in
Maven projects.
MockWebServer is used for firstly for internal testing, and for basic testing of apps using OkHttp client.
It is not a full featured HTTP testing library that is developed standalone. It is not being actively developed
for new features. As such you might find your needs outgrow MockWebServer and you may which to use a
more full featured testing library such as MockServer.
GraalVM Native Image
Building your native images with GraalVM should work automatically.
With this in place Java builds should fail if apps attempt to use internal packages.
error: package okhttp3.internal.platform is not visible
okhttp3.internal.platform.Platform.get();
^
(package okhttp3.internal.platform is declared in module okhttp3,
which does not export it to module com.bigco.sdk)
The stable public API is based on the list of defined modules:
okhttp3
okhttp3.brotli
okhttp3.coroutines
okhttp3.dnsoverhttps
okhttp3.java.net.cookiejar
okhttp3.logging
okhttp3.sse
okhttp3.tls
okhttp3.urlconnection
mockwebserver3
mockwebserver3.junit4
mockwebserver3.junit5
License
Copyright 2019 Square, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/square/okhttp là nguồn chính thức.
square/okhttp có bao nhiêu sao?
square/okhttp có 47.1k sao GitHub — tải lại trang để xem số mới nhất, hoặc xem trực tiếp github.com/square/okhttp. TopGit phản chiếu số sao của GitHub nhưng không cam kết đến từng phút.
square/okhttp có phải mã nguồn mở không?
Có — square/okhttp phát hành theo license Apache-2.0, nghĩa là mã nguồn mở để đọc, fork và (tùy license) tái sử dụng. Mã: github.com/square/okhttp.
square/okhttp còn đang phát triển không?
Commit gần nhất trên square/okhttp là 2 tháng trước (theo timestamp GitHub). Repo có 9.3k fork — một chỉ báo về mức độ quan tâm của cộng đồng.
square/okhttp là gì?
square/okhttp (square/okhttp) là dự án Kotlin trên GitHub. Theo mô tả gốc: A meticulous HTTP client for the JVM, Android, and GraalVM.
square/okhttp so với các dự án Mobile khác thế nào?
square/okhttp được TopGit xếp vào nhóm Mobile, với 47.1k sao GitHub và viết bằng Kotlin. Xem trang chủ đề Mobile trên TopGit để so sánh với các dự án tương tự theo số sao và mức độ hoạt động.
Đọc đầy đủ README ở tab phía trên.
Muốn nghe thêm một ý kiến về okhttp?
Hỏi một AI đọc được trang này — một cú bấm là có ngay nhận định về okhttp.