Nohttp

🍋 Android实现Http标准协议框架,支持多种缓存模式,底层可动态切换OkHttp、URLConn
Alternatives To Nohttp
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Okhttp Okgo10,444
9 months ago461apache-2.0Java
OkGo - 3.0 震撼来袭,该库是基于 Http 协议,封装了 OkHttp 的网络请求框架,比 Retrofit 更简单易用,支持 RxJava,RxJava2,支持自定义缓存,支持批量断点下载管理和批量上传管理功能
Nohttp3,7155215 years ago9August 25, 201872apache-2.0Java
:lemon: Android实现Http标准协议框架,支持多种缓存模式,底层可动态切换OkHttp、URLConnection。
Coderfun236
6 years ago1gpl-3.0Java
knowledge&girls,RxJava&Retrofit&DBFlow
Nohttprxutils219
5 years ago4Java
:tropical_fish: 本库是一款Android-Http标准协议网络通讯框架,基于RxJava+NoHttp封装。支持文件上传和断点续传、文件下载和断点下载、Http协议和Https协议队列网络请求、网络请求轮询。
Androidsdk76
4 years ago3mitJava
中国移动物联网开放平台 AndroidSDK
Jus561166 years ago12January 10, 201710apache-2.0Java
Flexible and Easy HTTP/REST Communication library for Java and Android
Oksimple56
5 months agoKotlin
OkSimple :powerful and simple okhttp network library
Elasticsearch Sql245
4 years ago1Java
基于Java Rest High Level Client的Elasticsearch-Sql组件【stalled】
Okhttprestassuredexamples28
8 months agoapache-2.0Java
API Testing using Rest-Assured and OkHttp.
Kinopoiskapi24
6 years ago1PHP
Unofficial Kinopoisk API
Alternatives To Nohttp
Select To Compare


Alternative Project Comparisons
Readme

NoHttp

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);

HTTP


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();

  1. addHeader()addParam()
  2. DiskCacheStore()``context.getCacheDir()``DiskCacheStore(path)``pathSDAndPermission

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

  1. IRequest
  2. NohttpRxUtils

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``AsyncTaskNoHttp

-AsyncRequestExecutor

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

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``NoHttpApp

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``OnResponseListener4NoHttp``SimpleResponseListener

Requestwhat``Handler``Message``what``OnResponseListenerRequestRequest

NoHttp``String``Bitmap``JSONObject``String``JSON``XML``JavaBean

  1. String``XML``JSON
  2. App

JavaBean``List``Map``Protobuf
http://blog.csdn.net/yanzhenjie1003/article/details/70158030

Request

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);

URL

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);

NoHttpSDSDNoHttp

6.0SDAndroid 6.0 AndPermission

  • 1Default http304E-TagLastModify
StringRequest request = new StringRequest(url, method);
request.setCacheMode(CacheMode.DEFAULT);
  • 2
StringRequest request = new StringRequest(url, method);
request.setCacheMode(CacheMode.REQUEST_NETWORK_FAILED_READ_CACHE);
  • 3 ImageLoader

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);
  • 4 http 304
ImageRequest request = new ImageRequest(url, method);
request.setCacheMode(CacheMode.ONLY_REQUEST_NETWORK);
...
  • 5
Request<Bitmap> request = NoHttp.createImageRequest(imageUrl);
request.setCacheMode(CacheMode.ONLY_READ_CACHE);

****Request``RequestNoHttp2.0

NoHttp``byte[]``byte[]``NoHttp``Request

NoHttp``RestRequest``RestRequest``parseResponse()

  • FastJsonRequest
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

-SyncDownloadExecutor

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

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``NoHttpURL


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

NoHttpdemoDownloadRequestbytebyte

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;
}

😄

License

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.
Popular Rest Projects
Popular Okhttp Projects
Popular Application Programming Interfaces Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Restful
Okhttp