您的位置:首页 > 其它

文章标题

2016-11-21 19:49 176 查看
上篇说到volley类,今天去看看HurlStack类和HttpClientStack类

//判断如果版本>=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;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: