AndroidHttp

Android Http网络开发神兵利器

APACHE-2.0 License

Stars
97

Android Http


[TOC]

AndroidAndroid Http [email protected]

AndroidAPPhttpSocketAndroid Http

Github

Http

HttpHttp3-5Http

HttpHttp

Http

HTTP

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

Request

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

Response

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

Code

:

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        // 

Method

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     

Header

HTTPCRLF

HTTP +++

Android http

URLConnection

URLConnectionJava JDKIOHttpsdksdk

Apache HttpClient

HttpClientApache Jakarta CommonHTTPHTTPHttpClientApache JakartaCactusHTMLUnitHttpClient

HttpClientJDKURLConnectionHttpHttp

AndroidApiHttpclient, .

HttpClient

Volley

Android Volley 2013Google I/OVolleyVolleyAsyncHttpClientUniversal-Image-LoaderAsyncHttpClientHTTPUniversal-Image-LoaderVolleyVolley

VolleyAndroid 2.3HttpURLConnectionAndroid 2.2HttpClientHttpURLConnectionbug

Volley

Volley

OkHttp & Retrofit

OkHttp Square,HttpUrlConnectionApache HttpClientOkHttp3Github

Retrofit SquareAndroidRetrofit2OkHttpOkHttpGoogleappOkHttp Github

OkHttpRetrofitAndroid

Charles

CharlesHTTP,HTTP,HTTPrequestresponseheaderscookiescachingMacCharlesWindowsfiddler

Charles

Charles

Http Https

Charlesmock api

Charles Mock

PostMan & Paw

Charles2http

PostmanHTTPChrome,

Api

http://news-at.zhihu.com/api/4/themes

Postman

Postman

Paw PostmanhttppostmanchromepostmanpawpawapiBTW, paw

Paw

Paw

Chrome Dev Tools

Chrome dev toolsGoogle Chrome

Chrome dev tools web

Chrome dev tools

Chrome dev tools

Chrome dev tools

curl

curlpoastmanpawcurl

curlURLUnixLinuxDOSWin32Win64

api

curlurl

postmanpawcurlcurlimcharlespawgoogle dev toolcurlcurlcurlapicurl

curl

curl

OkHttp

OkHttpOkHttp

logging-interceptor

apphttps

logging-interceptorokhttpclient

Stetho

StethoFacebookGoogle Chrome dev toolsStethoChromeAndroid

StethoSharePreferencerootviewStetho

stetho github

stetho

chuck

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

Chuck github

RESTful

RESTful

RESTRepresentational State TransferREST web 2000 Roy Fielding HTTP WebRESTSOAPSimple Object Access protocolXML-RPCURLPayloadRESTREST

Android HttpRESTfulRESTful

RESTful

HTTP

  • postman
  • paw
  • curl

AndroidWiresShark

  • Charles
  • Fiddler
  • WiresShark

Android HttpURLConnectionHTTP

  • URLConnection
  • HttpClient
  • Volley
  • OkHttp

OkHttpOkHttpOkHttpOkHttpOkHttp

  • logging-interceptor
  • Stetho
  • Chuck

App

Charles & Fiddler

AppAndroidiOSVolleyOkHttpHTTPmock

Httpsapphttpscharlesapphttps

app

OkHttp

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:

Aop

Aop

Assectj

Assectj Gradle

Http

Http

URLConnection

Android HttpClient

HttpClient

Volley

Volley

OkHttp

Retrofit Github

Charles

Charles Mock

Postman

Postman

Paw

Paw

Chrome dev tools

Chrome dev tools

Chrome dev tools

curl

curl

Interceptors

LoggingInterceptors

stetho github

stetho

Chuck github

RESTful

Aop

Aop

Assectj

Assectj Gradle