Android Http网络开发神兵利器
APACHE-2.0 License
[TOC]
AndroidAndroid Http [email protected]
AndroidAPPhttpSocketAndroid Http
HttpHttp3-5Http
HttpHttp
HTTPHyper Text Transfer Protocol,WWW:World Wide Web
HTTPTCP/IPHTML , ,
HTTP1990WWWHTTP/1.0HTTP/1.1HTTP-NG(Next Generation of HTTP)
HTTP-HTTPURLHTTPWEBWeb
1GETHEADPOSTHTTPHTTP
2HTTPContent-Type
4.HTTP
5B/SC/S
Http,Get
GET /562f25980001b1b106000338.jpg HTTP/1.1
Host img.mukewang.com
User-Agent Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.106 Safari/537.36
Accept image/webp,image/*,*/*;q=0.8
Referer http://www.imooc.com/
Accept-Encoding gzip, deflate, sdch
Accept-Language zh-CN,zh;q=0.8
,HTTP.
GETGET,[/562f25980001b1b106000338.jpg]HTTP1.1
HOST.User-Agent,,.,
Post
POST / HTTP1.1
Host:www.wrox.com
User-Agent:Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 3.5.21022)
Content-Type:application/x-www-form-urlencoded
Content-Length:40
Connection: Keep-Alive
name=Professional%20Ajax&publisher=Wiley
posthttp1.1
HTTP
HTTP
HTTP/1.1 200 OK
Date: Fri, 22 May 2009 06:07:21 GMT
Content-Type: text/html; charset=UTF-8
<html>
<head></head>
<body>
<!--body goes here-->
</body>
</html>
HTTP
HTTP/1.1HTTP1.1200ok
Date:Content-Type:MIMEHTML(text/html),UTF-8
html
:
1xx--
2xx--
3xx--
4xx--
5xx--
200 OK //
400 Bad Request //
401 Unauthorized // WWW-Authenticate
403 Forbidden //
404 Not Found // egURL
500 Internal Server Error //
503 Server Unavailable //
HTTPHTTP HTTP1.0 GET, POST HEAD HTTP1.1OPTIONS, PUT, DELETE, TRACE CONNECT
GET
HEAD get
POST POST/
PUT
DELETE
CONNECT HTTP/1.1
OPTIONS
TRACE
HTTPCRLF
HTTP +++
Android http
URLConnectionJava JDKIOHttpsdksdk
HttpClientApache Jakarta CommonHTTPHTTPHttpClientApache JakartaCactusHTMLUnitHttpClient
HttpClientJDKURLConnectionHttpHttp
Android Volley 2013Google I/OVolleyVolleyAsyncHttpClientUniversal-Image-LoaderAsyncHttpClientHTTPUniversal-Image-LoaderVolleyVolley
VolleyAndroid 2.3HttpURLConnectionAndroid 2.2HttpClientHttpURLConnectionbug
OkHttp Square,HttpUrlConnectionApache HttpClientOkHttp3Github
Retrofit SquareAndroidRetrofit2OkHttpOkHttpGoogleappOkHttp Github
OkHttpRetrofitAndroid
CharlesHTTP,HTTP,HTTPrequestresponseheaderscookiescachingMacCharlesWindowsfiddler
Charles
Http Https
Charlesmock api
Charles2http
PostmanHTTPChrome,
Api
http://news-at.zhihu.com/api/4/themes
Paw PostmanhttppostmanchromepostmanpawpawapiBTW, paw
Chrome dev toolsGoogle Chrome
Chrome dev tools web
curlpoastmanpawcurl
curlURLUnixLinuxDOSWin32Win64
api
curlurl
postmanpawcurlcurlimcharlespawgoogle dev toolcurlcurlcurlapicurl
OkHttpOkHttp
apphttps
logging-interceptor
okhttpclient
StethoFacebookGoogle Chrome dev toolsStethoChromeAndroid
StethoSharePreferencerootviewStetho
logcatchromechuck
chuck
Android
OkHttpClient
Gradle
dependencies {
debugCompile 'com.readystatesoftware.chuck:library:1.0.4'
releaseCompile 'com.readystatesoftware.chuck:library-no-op:1.0.4'
}
OkHttpClient client = new OkHttpClient.Builder()
.addInterceptor(new ChuckInterceptor(context))
.build();
RESTful
RESTRepresentational State TransferREST web 2000 Roy Fielding HTTP WebRESTSOAPSimple Object Access protocolXML-RPCURLPayloadRESTREST
Android HttpRESTfulRESTful
HTTP
AndroidWiresShark
Android HttpURLConnectionHTTP
OkHttpOkHttpOkHttpOkHttpOkHttp
App
AppAndroidiOSVolleyOkHttpHTTPmock
Httpsapphttpscharlesapphttps
app
OKHttpAndroidAppOkHttpHttpsapp
App
OkHttpOkHttpClient
AopOkHttpClientAppsdksdkOKhttpsdk
:
gradle_plugin_android_aspectjx
dependencies {
classpath 'com.hujiang.aspectjx:gradle-android-plugin-aspectjx:1.0.9'
}
Aspectj
import com.facebook.stetho.okhttp3.StethoInterceptor;
import com.readystatesoftware.chuck.ChuckInterceptor;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import me.ele.breakfastapp.AppContext;
import okhttp3.OkHttpClient;
@Aspect
public class OkHttpAspect {
@Pointcut("call(public okhttp3.OkHttpClient build())")
public void build() {
}
@Around("build()")
public Object aroundBuild(ProceedingJoinPoint joinPoint) throws Throwable {
Object target = joinPoint.getTarget();
if (target instanceof OkHttpClient.Builder) {
OkHttpClient.Builder builder = (OkHttpClient.Builder) target;
builder.addNetworkInterceptor(new StethoInterceptor());
builder.addNetworkInterceptor(new ChuckInterceptor(AppContext.get()));
}
return joinPoint.proceed();
}
}
Aop: