文章标题
2016-11-21 19:49
176 查看
上篇说到volley类,今天去看看HurlStack类和HttpClientStack类
可见HurlStack和HttpClientStack都实现了HttpStack
//判断如果版本>=9,使用HttpURLConnection,否则使用HttpClient if (Build.VERSION.SDK_INT >= 9) { stack = new HurlStack(); } else { // Prior to Gingerbread, HttpUrlConnection was unreliable. // See: http://android-developers.blogspot.com/2011/09/androids-http-clients.html stack = new HttpClientStack(AndroidHttpClient.newInstance(userAgent)); }
可见HurlStack和HttpClientStack都实现了HttpStack
public class HurlStack implements HttpStack {...}
public class HttpClientStack implements HttpStack {...}
/** * 一个抽象http栈 * An HTTP stack abstraction. */ public interface HttpStack { /** * 执行请求 * Performs an HTTP request with the given parameters. * * <p>A GET request is sent if request.getPostBody() == null. A POST request is sent otherwise, * and the Content-Type header is set to request.getPostBodyContentType().</p> * * @param request the request to perform * @param additionalHeaders additional headers to be sent together with * {@link Request#getHeaders()} * @return the HTTP response */ public HttpResponse performRequest(Request<?> request, Map<String, String> additionalHeaders) throws IOException, AuthFailureError; }