/*
Android Asynchronous Http Client
Copyright (c) 2011 James Smith <james@loopj.com>
http://loopj.com
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.
*/
package com.loopj.android.http;
import android.content.Context;
import android.util.Log;
import org.apache.http.Header;
import org.apache.http.HeaderElement;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
import org.apache.http.HttpRequest;
import org.apache.http.HttpRequestInterceptor;
import org.apache.http.HttpResponse;
import org.apache.http.HttpResponseInterceptor;
import org.apache.http.HttpVersion;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.UsernamePasswordCredentials;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpUriRequest;
import org.apache.http.client.protocol.ClientContext;
import org.apache.http.conn.params.ConnManagerParams;
import org.apache.http.conn.params.ConnPerRouteBean;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.entity.HttpEntityWrapper;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.client.DefaultRedirectHandler;
import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.protocol.SyncBasicHttpContext;
import java.io.IOException;
import java.io.InputStream;
import java.lang.ref.WeakReference;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.WeakHashMap;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.zip.GZIPInputStream;
/**
* The AsyncHttpClient can be used to make asynchronous GET, POST, PUT and
* DELETE HTTP requests in your Android applications. Requests can be made
* with additional parameters by passing a {@link RequestParams} instance,
* and responses can be handled by passing an anonymously overridden
* {@link AsyncHttpResponseHandler} instance.
* <p> </p>
* For example:
* <p> </p>
* <pre>
* AsyncHttpClient client = new AsyncHttpClient();
* client.get("http://www.google.com", new AsyncHttpResponseHandler() {
* @Override
* public void onSuccess(String response) {
* System.out.println(response);
* }
* });
* </pre>
*/
public class AsyncHttpClient {
private static final String VERSION = "1.4.4";
private static final int DEFAULT_MAX_CONNECTIONS = 10;
private static final int DEFAULT_SOCKET_TIMEOUT = 10 * 1000;
private static final int DEFAULT_MAX_RETRIES = 5;
private static final int DEFAULT_RETRY_SLEEP_TIME_MILLIS = 1500;
private static final int DEFAULT_SOCKET_BUFFER_SIZE = 8192;
private static final String HEADER_ACCEPT_ENCODING = "Accept-Encoding";
private static final String ENCODING_GZIP = "gzip";
private static final String LOG_TAG = "AsyncHttpClient";
private int maxConnections = DEFAULT_MAX_CONNECTIONS;
private int timeout = DEFAULT_SOCKET_TIMEOUT;
private final DefaultHttpClient httpClient;
private final HttpContext httpContext;
private ThreadPoolExecutor threadPool;
private final Map<Context, List<WeakReference<Future<?>>>> requestMap;
private final Map<String, String> clientHeaderMap;
private boolean isUrlEncodingEnabled = true;
/**
* Creates a new AsyncHttpClient with default constructor arguments values
*/
public AsyncHttpClient() {
this(false, 80, 443);
}
/**
* Creates a new AsyncHttpClient.
*
* @param httpPort non-standard HTTP-only port
*/
public AsyncHttpClient(int httpPort) {
this(false, httpPort, 443);
}
/**
* Creates a new AsyncHttpClient.
*
* @param httpPort non-standard HTTP-only port
* @param httpsPort non-standard HTTPS-only port
*/
public AsyncHttpClient(int httpPort, int httpsPort) {
this(false, httpPort, httpsPort);
}
/**
* Creates new AsyncHttpClient using given params
*
* @param fixNoHttpResponseException Whether to fix or not issue, by ommiting SSL verification
* @param httpPort HTTP port to be used, must be greater than 0
* @param httpsPort HTTPS port to be used, must be greater than 0
*/
public AsyncHttpClient(boolean fixNoHttpResponseException, int httpPort, int httpsPort) {
this(getDefaultSchemeRegistry(fixNoHttpResponseException, httpPort, httpsPort));
}
/**
* Returns default instance of SchemeRegistry
*
* @param fixNoHttpResponseException Whether to fix or not issue, by ommiting SSL verification
* @param httpPort HTTP port to be used, must be greater than 0
* @param httpsPort HTTPS port to be used, must be greater than 0
*/
private static SchemeRegistry getDefaultSchemeRegistry(boolean fixNoHttpResponseException, int httpPort, int httpsPort) {
if (fixNoHttpResponseException) {
Log.d(LOG_TAG, "Beware! Using the fix is insecure, as it doesn't verify SSL certificates.");
}
if (httpPort < 1) {
httpPort = 80;
Log.d(LOG_TAG, "Invalid HTTP port number specified, defaulting to 80");
}
if (httpsPort < 1) {
httpsPort = 443;
Log.d(LOG_TAG, "Invalid HTTPS port number specified, defaulting to 443");
}
// Fix to SSL flaw in API < ICS
// See https://code.google.com/p/android/issues/detail?id=13117
SSLSocketFactory sslSocketFactory;
if (fixNoHttpResponseException)
sslSocketFactory = MySSLSocketFactory.getFixedSocketFactory();
else
sslSocketFactory = SSLSocketFactory.getSocketFactory();
SchemeRegistry schemeRegistry = new SchemeRegistry();
schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), httpPort));
schemeRegistry.register(new Scheme("https", sslSocketFactory, httpsPort));
return schemeRegistry;
}
/**
* Creates a new AsyncHttpClient.
*
* @param schemeRegistry SchemeRegistry to be used
*/
public AsyncHttpClient(SchemeRegistry schemeRegistry) {
BasicHttpParams httpParams = new BasicHttpParams();
ConnManagerParams.setTimeout(httpParams, timeout);
ConnManagerParams.setMaxConnectionsPerRoute(httpParams, new ConnPerRouteBean(maxConnections));
ConnManagerParams.setMaxTotalConnections(httpParams, DEFAULT_MAX_CONNECTIONS);
HttpConnectionParams.setSoTimeout(httpParams, timeout);
没有合适的资源?快使用搜索试试~ 我知道了~
【张泽华】android视频教程上课源代码
共3278个文件
class:943个
xml:701个
png:611个
5星 · 超过95%的资源 需积分: 10 1.8k 下载量 51 浏览量
2014-04-01
23:55:26
上传
评论 31
收藏 67.49MB RAR 举报
温馨提示
这是我边看张泽华老师的视频教程,边敲出来的代码,里边总共有71个工程,是枕套视频的源代码,总体上是跟张老师上课的一样的
资源推荐
资源详情
资源评论
收起资源包目录
【张泽华】android视频教程上课源代码 (3278个子文件)
IService.aidl 80B
IService.aidl 80B
IService.aidl 80B
IService.aidl 80B
IService.aidl 80B
IService.aidl 80B
resources.ap_ 1.41MB
resources.ap_ 177KB
resources.ap_ 105KB
resources.ap_ 105KB
resources.ap_ 79KB
resources.ap_ 59KB
resources.ap_ 50KB
resources.ap_ 43KB
resources.ap_ 42KB
resources.ap_ 42KB
resources.ap_ 42KB
resources.ap_ 41KB
resources.ap_ 41KB
resources.ap_ 41KB
resources.ap_ 41KB
resources.ap_ 41KB
resources.ap_ 41KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 40KB
resources.ap_ 34KB
resources.ap_ 33KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 11KB
resources.ap_ 10KB
resources.ap_ 10KB
resources.ap_ 10KB
resources.ap_ 10KB
resources.ap_ 10KB
resources.ap_ 10KB
resources.ap_ 10KB
65_itheima_frameanimation.apk 1.62MB
26_itheima_uploadfile.apk 436KB
49_itheima_beauty.apk 387KB
53_itheima_imgcolor.apk 316KB
54_itheima_imgcompound.apk 315KB
68_itheima_pointer.apk 290KB
25_itheima_passdata2ServerByAsyncHttp.apk 272KB
56_itheima_soundpool.apk 261KB
27_itheima_smartimageview.apk 255KB
28_itheima_downloadfile.apk 254KB
34_itheima_smsSender.apk 254KB
67_itheima_xmltween.apk 253KB
71_itheima_tab.apk 253KB
57_itheima_videoplayer.apk 252KB
58_itheima_myCarema.apk 252KB
52_itheima_imgtranslate.apk 252KB
42_itheima_activity_lifecycle.apk 252KB
59_itheima_dialog.apk 252KB
29_itheima_explicitintent.apk 251KB
70_itheima_fragment.apk 251KB
55_itheima_musicplayer.apk 251KB
55_itheima_musicplayer.apk 251KB
40_itheima_config_implictintent.apk 251KB
41_itheima_intent_send_data.apk 251KB
66_itheima_tween.apk 251KB
66_itheima_tween.apk 251KB
44_itheima_loadimg.apk 251KB
20_itheima_wirteContact.apk 250KB
19_itheima_contact.apk 250KB
69_itheima_installer.apk 250KB
39_itheima_implicitintent.apk 250KB
45_itheima_readexif.apk 250KB
50_itheima_imgzoom.apk 250KB
61_itheima_menu.apk 250KB
62_itheima_style.apk 250KB
51_itheima_imgrotate.apk 250KB
47_itheima_canvas.apk 250KB
共 3278 条
- 1
- 2
- 3
- 4
- 5
- 6
- 33
reality_jie
- 粉丝: 112
- 资源: 11
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
- 5
- 6
前往页