Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Okhttp Okgo | 10,444 | 9 months ago | 461 | apache-2.0 | Java | |||||
OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能 | ||||||||||
Nohttp | 3,715 | 52 | 1 | 5 years ago | 9 | August 25, 2018 | 72 | apache-2.0 | Java | |
:lemon: Android实现Http标准协议框架,支持多种缓存模式,底层可动态切换OkHttp、URLConnection。 | ||||||||||
Coderfun | 236 | 6 years ago | 1 | gpl-3.0 | Java | |||||
knowledge&girls,RxJava&Retrofit&DBFlow | ||||||||||
Nohttprxutils | 219 | 5 years ago | 4 | Java | ||||||
:tropical_fish: 本库是一款Android-Http标准协议网络通讯框架,基于RxJava+NoHttp封装。支持文件上传和断点续传、文件下载和断点下载、Http协议和Https协议队列网络请求、网络请求轮询。 | ||||||||||
Androidsdk | 76 | 4 years ago | 3 | mit | Java | |||||
中国移动物联网开放平台 AndroidSDK | ||||||||||
Jus | 56 | 1 | 16 | 6 years ago | 12 | January 10, 2017 | 10 | apache-2.0 | Java | |
Flexible and Easy HTTP/REST Communication library for Java and Android | ||||||||||
Oksimple | 56 | 5 months ago | Kotlin | |||||||
OkSimple :powerful and simple okhttp network library | ||||||||||
Elasticsearch Sql2 | 45 | 4 years ago | 1 | Java | ||||||
基于Java Rest High Level Client的Elasticsearch-Sql组件【stalled】 | ||||||||||
Okhttprestassuredexamples | 28 | 8 months ago | apache-2.0 | Java | ||||||
API Testing using Rest-Assured and OkHttp. | ||||||||||
Kinopoiskapi | 24 | 6 years ago | 1 | PHP | ||||||
Unofficial Kinopoisk API |
QQ46505645
****KalleKalleApi
Kalleyanzhenjie/Kalle
Kallehttp://yanzhenjie.github.io/Kalle
NoHttp
HttpURLConnection
implementation 'com.yanzhenjie.nohttp:nohttp:1.1.11'
OkHttp
implementation 'com.yanzhenjie.nohttp:okhttp:1.1.11'
NoHttp.initialize(this);
InitializationConfig config = InitializationConfig.newBuilder(context)
//
...
.build();
NoHttp.initialize(config);
InitializationConfig config = InitializationConfig.newBuilder(context)
// 10s
.connectionTimeout(30 * 1000)
// 10s
.readTimeout(30 * 1000)
// DBCacheStoreSDDiskCacheStore
.cacheStore(
// setEnable(false)
new DBCacheStore(context).setEnable(true)
)
// CookieDBCookieStoreCookieStore
.cookieStore(
// cookiesetEnable(false)
new DBCookieStore(context).setEnable(true)
)
// URLConnectionNetworkExecutorOkHttpOkHttpNetworkExecutor
.networkExecutor()
// Headeraddaddadd
.addHeader()
// Paramaddaddadd
.addParam()
.sslSocketFactory() // SSLSocketFactory
.hostnameVerifier() // HostnameVerifier
.retry(x) // x
.build();
DiskCacheStore()``context.getCacheDir()``DiskCacheStore(path)``path
SDAndPermission
SD
InitializationConfig config = InitializationConfig.newBuilder(context)
.cacheStore(
new DiskCacheStore(context) // context.getCahceDir()
// new DiskCacheStore(path) // pathpath
)
.build();
InitializationConfig config = InitializationConfig.newBuilder(context)
.addHeader("Token", "123") //
.addHeader("Token", "456") //
.addParam("AppVersion", "1.0.0") //
.addParam("AppType", "Android") //
.addParam("AppType", "iOS") //
.build();
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Logger.setDebug(true);// NoHttp,
Logger.setTag("NoHttpSample");// Logtag
NoHttpCookieLog
NoHttp``NoHttp``AsyncRequestExecutor``RequestQueue``RxJava``AsyncTask``NoHttp``String
StringRequest request = new String(url, RequestMethod.GET);
Response<String> response = SyncRequestExecutor.INSTANCE.execute(request);
if (response.isSucceed()) {
//
} else {
//
Exception e = response.getException();
}
RxJava + NoHttp
NoHttp``SyncRequestExecutor``NoHttp``AsyncRequestExecutor``RequestQueue
String
StringRequest req = new String("http://api.nohttp.net" RequestMethod.POST);
Response<String> response = SyncRequestExecutor.INSTANCE.execute(req);
if (response.isSucceed()) {
//
} else {
//
Exception e = response.getException();
}
****AndroidRxJava``AsyncTask
NoHttp
StringRequest request = new StringRequest("http://api.nohttp.net");
Cancelable cancel = AsyncRequestExecutor.INSTANCE.execute(0, request, new SimpleResponseListener<String>() {
@Override
public void onSucceed(int what, Response<String> response) {
//
}
@Override
public void onFailed(int what, Response<String> response) {
//
}
});
//
cancel.cancel();
//
boolean isCancelled = cancel.isCancelled();
RequestQueue queue = NoHttp.newRequestQueue(); //
...
//
queue.add(what, request, listener);
...
// CPU
queue.stop();
//
RequestQueue queue = new RequestQueue(5);
queue.start(); //
...
//
queue.add(what, request, listener);
...
//
queue.stop();
new****
public <T> void request(Request<T> request, SampleResponseListener<T> listener) {
RequestQueue queue = NoHttp.newRequestQueue(5);
queue.add(0, request, listener);
}
NoHttp
//
NoHttp.getRequestQueueInstance().add...
...
//
NoHttp.getDownloadQueueInstance().add...
AsyncRequestExecutor
queue.stop()
Appqueue.stop()``RequestQueue
BaseActivity``onCreate()``RequestQueue``onDestory()
public class BaseActivity extends Activity {
private RequestQueue queue;
@Override
public void onCreate(Bundle savedInstanceState) {
queue = NoHttp.newRequestQueue();
}
//
public <T> void request(int what, Request<T> request, SimpleResponseListener<T> listener) {
queue.add(what, request, listener);
}
@Override
public void onDestory() {
queue.stop();
}
}
RequestQueue
StringRequest request = new StringRequest("http://api.nohttp.net", RequestMethod.POST);
CallServer.getInstance().request(0, request, listener);
CallServer``NoHttp
App
public class CallServer {
private static CallServer instance;
public static CallServer getInstance() {
if (instance == null)
synchronized (CallServer.class) {
if (instance == null)
instance = new CallServer();
}
return instance;
}
private RequestQueue queue;
private CallServer() {
queue = NoHttp.newRequestQueue(5);
}
public <T> void request(int what, Request<T> request, SimpleResponseListener<T> listener) {
queue.add(what, request, listener);
}
// appCPU
public void stop() {
queue.stop();
}
}
****listener``interface``OnResponseListener
4NoHttp``SimpleResponseListener
Request
what``Handler``Message``what``OnResponseListener
RequestRequest
NoHttp``String``Bitmap``JSONObject``String``JSON``XML``JavaBean
String``XML``JSON
JavaBean``List``Map``Protobuf
http://blog.csdn.net/yanzhenjie1003/article/details/70158030
NoHttp``Request``NoHttp``String``Bitmap``JSONObject``JSONArray``Request
// String
StringRequest request = new StringRequest(url, method);
// Bitmap
ImageRequest request = new ImageRequest(url, method);
// JSONObject
JsonObjectRequest request = new JsonObjectRequest(url, method);
// JSONArray
JsonArrayRequest request = new JsonArrayRequest(url, method);
1.1.3URLRESTFULAPIURL
http://api.nohttp.net/rest/<userid>/userinfo
<userid>
id
String userName = AppConfig.getUserName();
String url = "http://api.nohttp.net/rest/%1$s/userinfo";
url = String.format(Locale.getDefault(), url, userName);
StringRequest request = new StringRequest(url);
...
String url = "http://api.nohttp.net/rest/";
StringRequest request = new StringRequest(url)
request.path(AppConfig.getUserName())
request.path("userinfo")
...
URL
String``int``long``double``float
StringRequest request = new StringRequest(url, RequestMethod.POST);
.addHeader("name", "yanzhenjie") // String
.addHeader("age", "18") // int
.setHeader("sex", "") // setHeaderkey
...
Binary``File``String``int``long``double``float
StringRequest request = new StringRequest(url, RequestMethod.POST);
.add("name", "") // String
.add("age", 18) // int
.add("age", "20") // addkeyage18, 20
.set("sex", "") // setkey
.set("sex", "") // sex
// File
.add("head", file)
.add("head", new FileBinary(file))
// Bitmap
.add("head", new BitmapBinary(bitmap))
// ByteArray
.add("head", new ByteArrayBinary(byte[]))
// InputStream
.add("head", new InputStreamBinary(inputStream));
Request#add(Map<String, String>)``Request#add(Map<String, Object>)``Map``Map
StringFileBinaryList<String>List<Binary>List<File>List<Object>
Map<String, Object> params = new HashMap<>();
params.put("name", "yanzhenjie");
params.put("head", new File(path));
params.put("logo", new FileBinary(file));
params.put("age", 18);
params.put("height", 180.5);
List<String> hobbies = new ArrayList<>();
hobbies.add("");
hobbies.add("");
params.put("hobbies", hobbies);
List<File> goods = new ArrayList<>();
goods.add(file1);
goods.add(file2);
params.put("goods", goods);
List<Object> otherParams = new ArrayList<>();
otherParams.add("yanzhenjie");
otherParams.add(1);
otherParams.add(file);
otherParams.add(new FileBinary(file));
params.put("other", otherParams);
key``String``int``key
request body
StringRequest request = ...
request.add("file", new FileBinary(file));
key
File``Bitmap``InputStream``ByteArray
StringRequest request = ...
request.add("file1", new FileBinary(File));
request.add("file2", new FileBinary(File));
request.add("file3", new InputStreamBinary(InputStream));
request.add("file4", new ByteArrayBinary(byte[]));
request.add("file5", new BitmapBinary(Bitmap));
key
StringRequest request = ...
fileList.add("image", new FileBinary(File));
fileList.add("image", new InputStreamBinary(InputStream));
fileList.add("image", new ByteArrayBinary(byte[]));
fileList.add("image", new BitmapBinary(Bitmap));
StringRequest request = ...;
List<Binary> fileList = ...;
fileList.add(new FileBinary(File));
fileList.add(new InputStreamBinary(InputStream));
fileList.add(new ByteArrayBinary(byte[]));
fileList.add(new BitmapStreamBinary(Bitmap));
request.add("file_list", fileList);
request body
****
BodyJson``String``Xml
// String
request.setDefineRequestBody(String, ContentType);
// json
request.setDefineRequestBodyForJson(JsonString)
// jsonObjectjson
request.setDefineRequestBodyForJson(JSONObject)
// xml
request.setDefineRequestBodyForXML(XmlString)
// BodyFileInputStream
request.setDefineRequestBody(InputStream, ContentType)
File file = ...;
FileInputStream fileStream = new FileInputStream(file);
StringRequest request = new StringRequest(url, RequestMethod.POST);
request.setDefineRequestBody(fileStream, Headers.HEAD_VALUE_CONTENT_TYPE_OCTET_STREAM);
NoHttp
SDSDNoHttp
6.0SDAndroid 6.0 AndPermission
Default
http304E-TagLastModifyStringRequest request = new StringRequest(url, method);
request.setCacheMode(CacheMode.DEFAULT);
StringRequest request = new StringRequest(url, method);
request.setCacheMode(CacheMode.REQUEST_NETWORK_FAILED_READ_CACHE);
String``String
StringRequest request = new StringRequest(url, method);
// HttpIF_NONE_CACHE_REQUEST_NETWORK
request.setCacheMode(CacheMode.IF_NONE_CACHE_REQUEST_NETWORK);
ImageRequest request = new ImageRequest(url, method);
request.setCacheMode(CacheMode.IF_NONE_CACHE_REQUEST_NETWORK);
ImageRequest request = new ImageRequest(url, method);
request.setCacheMode(CacheMode.ONLY_REQUEST_NETWORK);
...
Request<Bitmap> request = NoHttp.createImageRequest(imageUrl);
request.setCacheMode(CacheMode.ONLY_READ_CACHE);
****Request``Request
NoHttp2.0
NoHttp``byte[]``byte[]``NoHttp``Request
NoHttp``RestRequest``RestRequest``parseResponse()
public class FastJsonRequest extends RestRequestor<JSONObject> {
public FastJsonRequest(String url) {
this(url, RequestMethod.GET);
}
public FastJsonRequest(String url, RequestMethod requestMethod) {
super(url, requestMethod);
}
@Override
public JSONObject parseResponse(Headers header, byte[] body) throws Throwable {
String result = StringRequest.parseResponseString(headers, body);
return JSON.parseObject(result);
}
}
Request``JavaBean``List
http://blog.csdn.net/yanzhenjie1003/article/details/70158030
demo
NoHttp``SyncDownloadExecutor``NoHttp``DownloadQueue``SyncDownloadExecutor``RxJava``AsyncTask
DownloadRequest request = new DownloadRequest(url, RequestMethod.GET, fileFolder, true, true);
SyncDownloadExecutor.INSTANCE.execute(0, request, new SimpleDownloadListener() {
@Override
public void onStart(int what, boolean resume, long range, Headers headers, long size) {
//
// 1what
// 2
// 30
// 4
// 50
}
@Override
public void onProgress(int what, int progress, long fileCount, long speed) {
//
// 1what
// 2[0-100]
// 30
// 41Sbyte
// int xKB = (int) speed / 1024; // xKB/S
// int xM = (int) speed / 1024 / 1024; // xM/S
}
@Override
public void onFinish(int what, String filePath) {
// 2
}
});
DownloadListener``NoHttp``SimpleDownloadListener``DownloadListener
private DownloadListener downloadListener = new DownloadListener() {
@Override
public void onStart(int what, boolean resume, long preLenght, Headers header, long count) {
//
}
@Override
public void onProgress(int what, int progress, long downCount, long speed) {
//
}
@Override
public void onFinish(int what, String filePath) {
//
}
@Override
public void onDownloadError(int what, StatusCode code, CharSequence message) {
//
// 2javaDocdemo
//
}
@Override
public void onCancel(int what) {
//
}
};
DownloadQueue queue = NoHttp.newDownloadQueue(); //
...
//
queue.add(what, request, listener);
...
// CPU
queue.stop();
//
RequestQueue queue = new RequestQueue(5);
queue.start(); //
...
//
queue.add(what, request, listener);
...
// CPU
queue.stop();
RequestQueue``RequestQueue
NoHttp``NoHttp
URL
DownloadRequest req = new DownloadRequest(url, method, folder, filename, range, deleteOld);
// 1url
// 2GET
// 3
// 4
// 550%50%0
// 6
String url = "http://...";
String folder = ...;
String filename = "xx.apk";
DownloadRequest req = new DownloadRequest(url, RequestMethod.GET, folder, filename, true, true);
NoHttp``url``Content-Disposition
DownloadRequest req = new DownloadRequest(url, method, folder, range, deleteOld);
//
****NoHttp
Http``tomcat``apache``nginx``iis
NoHttp
demoDownloadRequest
bytebyte
DownloadRequest request;
String url = "http://...";
//
public void startDownload() {
if(request != null)
request = new DownloadRequest(url, RequestMethod.GET, "/sdcard/", "xx.apk", true, true);
// 5true
}
//
public void stopDownload() {
if(downloadRequest != null)
downloadRequest.cancel();
}
sample
HttpsNoHttpHttps
-keepclassmembers class ** {
private javax.net.ssl.SSLSocketFactory delegate;
}
😄
Copyright 2015 Yan Zhenjie
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.