Request
Volley中的请求对象,而Network 就是请求Request的。
Request构造
1
2
3
4
5
6
7
8
9 |
<span> public
Request( int
method, String url, Response.ErrorListener listener) { mMethod = method; mUrl = url; mErrorListener = listener; setRetryPolicy( new
DefaultRetryPolicy()); mDefaultTrafficStatsTag = findDefaultTrafficStatsTag(url); } </span> |
创建一个请求;这个需要有请求方式:method。GET POST 之类的,然后请求的url. 还有一个就是。如果请求成功回调的方法,listener,请求失败回掉的方法listener 执行他的。
其中setRetryPolicy()为重试策略,(这边还没有看,猜测 就是如果没有连接成功 重新连接的策略)
mDefaultTrafficStatsTag 先判断Url是否为空,如果不为空,判断Uri.parse(url);是否能转换成uri 转换成功后返回uri字符串.Hashcode();
然后再根据一系列的操作,从这个请求中network读取对应的信息:
/** * Request method of this request. Currently supports GET, POST, PUT, * DELETE, HEAD, OPTIONS, TRACE, and PATCH. */ private final int mMethod; /** URL of this request. */ private final String mUrl; /** Default tag for {@link TrafficStats}. */ private final int mDefaultTrafficStatsTag; /** Listener interface for errors. */ private final Response.ErrorListener mErrorListener; /** Sequence number of this request, used to enforce FIFO ordering. */ private Integer mSequence; /** The request queue this request is associated with. */ private RequestQueue mRequestQueue; /** Whether or not responses to this request should be cached. */ private boolean mShouldCache = true; /** Whether or not this request has been canceled. */ private boolean mCanceled = false; /** Whether or not a response has been delivered for this request yet. */ private boolean mResponseDelivered = false; // A cheap variant of request tracing used to dump slow requests. private long mRequestBirthTime = 0; /** * Threshold at which we should log the request (even when debug logging is * not enabled). */ private static final long SLOW_REQUEST_THRESHOLD_MS = 3000; /** The retry policy for this request. */ private RetryPolicy mRetryPolicy; /** * When a request can be retrieved from cache but must be refreshed from the * network, the cache entry will be stored here so that in the event of a * "Not Modified" response, we can be sure it hasn‘t been evicted from * cache. */ private Cache.Entry mCacheEntry = null; /** An opaque token tagging this request; used for bulk cancellation. */ private Object mTag;
【深蓝】Volley之Request 2,布布扣,bubuko.com
原文:http://www.cnblogs.com/a-blue/p/3671370.html