// AVHTTPClient.h
//
// Copyright (c) 2011 Gowalla (http://gowalla.com/)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
#import <Foundation/Foundation.h>
#import <Availability.h>
#import <SystemConfiguration/SystemConfiguration.h>
#import <MobileCoreServices/MobileCoreServices.h>
/**
`AVHTTPClient` captures the common patterns of communicating with an web application over HTTP. It encapsulates information like base URL, authorization credentials, and HTTP headers, and uses them to construct and manage the execution of HTTP request operations.
## Automatic Content Parsing
Instances of `AVHTTPClient` may specify which types of requests it expects and should handle by registering HTTP operation classes for automatic parsing. Registered classes will determine whether they can handle a particular request, and then construct a request operation accordingly in `enqueueHTTPRequestOperationWithRequest:success:failure`.
## Subclassing Notes
In most cases, one should create an `AVHTTPClient` subclass for each website or web application that your application communicates with. It is often useful, also, to define a class method that returns a singleton shared HTTP client in each subclass, that persists authentication credentials and other configuration across the entire application.
## Methods to Override
To change the behavior of all url request construction for an `AVHTTPClient` subclass, override `requestWithMethod:path:parameters`.
To change the behavior of all request operation construction for an `AVHTTPClient` subclass, override `HTTPRequestOperationWithRequest:success:failure`.
## Default Headers
By default, `AVHTTPClient` sets the following HTTP headers:
- `Accept-Language: (comma-delimited preferred languages), en-us;q=0.8`
- `User-Agent: (generated user agent)`
You can override these HTTP headers or define new ones using `setDefaultHeader:value:`.
## URL Construction Using Relative Paths
Both `-requestWithMethod:path:parameters:` and `-multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:` construct URLs from the path relative to the `-baseURL`, using `NSURL +URLWithString:relativeToURL:`. Below are a few examples of how `baseURL` and relative paths interact:
NSURL *baseURL = [NSURL URLWithString:@"http://example.com/v1/"];
[NSURL URLWithString:@"foo" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"foo?bar=baz" relativeToURL:baseURL]; // http://example.com/v1/foo?bar=baz
[NSURL URLWithString:@"/foo" relativeToURL:baseURL]; // http://example.com/foo
[NSURL URLWithString:@"foo/" relativeToURL:baseURL]; // http://example.com/v1/foo
[NSURL URLWithString:@"/foo/" relativeToURL:baseURL]; // http://example.com/foo/
[NSURL URLWithString:@"http://example2.com/" relativeToURL:baseURL]; // http://example2.com/
Also important to note is that a trailing slash will be added to any `baseURL` without one, which would otherwise cause unexpected behavior when constructing URLs using paths without a leading slash.
## NSCoding / NSCopying Conformance
`AVHTTPClient` conforms to the `NSCoding` and `NSCopying` protocols, allowing operations to be archived to disk, and copied in memory, respectively. There are a few minor caveats to keep in mind, however:
- Archives and copies of HTTP clients will be initialized with an empty operation queue.
- NSCoding cannot serialize / deserialize block properties, so an archive of an HTTP client will not include any reachability callback block that may be set.
*/
#ifdef _SYSTEMCONFIGURATION_H
typedef enum {
AVNetworkReachabilityStatusUnknown = -1,
AVNetworkReachabilityStatusNotReachable = 0,
AVNetworkReachabilityStatusReachableViaWWAN = 1,
AVNetworkReachabilityStatusReachableViaWiFi = 2,
} AVNetworkReachabilityStatus;
#else
#warning SystemConfiguration framework not found in project, or not included in precompiled header. Network reachability functionality will not be available.
#endif
#ifndef __UTTYPE__
#if __IPHONE_OS_VERSION_MIN_REQUIRED
#warning MobileCoreServices framework not found in project, or not included in precompiled header. Automatic MIME type detection when uploading files in multipart requests will not be available.
#else
#warning CoreServices framework not found in project, or not included in precompiled header. Automatic MIME type detection when uploading files in multipart requests will not be available.
#endif
#endif
typedef enum {
AVFormURLParameterEncoding,
AVJSONParameterEncoding,
AVPropertyListParameterEncoding,
} AVHTTPClientParameterEncoding;
@class AVHTTPRequestOperation;
@protocol AVMultipartFormData;
@interface AVHTTPClient : NSObject <NSCoding, NSCopying>
///---------------------------------------
/// @name Accessing HTTP Client Properties
///---------------------------------------
/**
The url used as the base for paths specified in methods such as `getPath:parameters:success:failure`
*/
@property (readonly, nonatomic) NSURL *baseURL;
/**
The string encoding used in constructing url requests. This is `NSUTF8StringEncoding` by default.
*/
@property (nonatomic, assign) NSStringEncoding stringEncoding;
/**
The `AVHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body. This is `AVFormURLParameterEncoding` by default.
@warning Some nested parameter structures, such as a keyed array of hashes containing inconsistent keys (i.e. `@{@"": @[@{@"a" : @(1)}, @{@"b" : @(2)}]}`), cannot be unambiguously represented in query strings. It is strongly recommended that an unambiguous encoding, such as `AVJSONParameterEncoding`, is used when posting complicated or nondeterministic parameter structures.
*/
@property (nonatomic, assign) AVHTTPClientParameterEncoding parameterEncoding;
/**
The operation queue which manages operations enqueued by the HTTP client.
*/
@property (readonly, nonatomic) NSOperationQueue *operationQueue;
/**
The reachability status from the device to the current `baseURL` of the `AVHTTPClient`.
@warning This property requires the `SystemConfiguration` framework. Add it in the active target's "Link Binary With Library" build phase, and add `#import <SystemConfiguration/SystemConfiguration.h>` to the header prefix of the project (`Prefix.pch`).
*/
#ifdef _SYSTEMCONFIGURATION_H
@property (readonly, nonatomic, assign) AVNetworkReachabilityStatus networkReachabilityStatus;
#endif
///---------------------------------------------
/// @name Creating and Initializing HTTP Clients
///---------------------------------------------
/**
Creates and initializes an `AVHTTPClient` object with the specified base URL.
@param url The base URL for the HTTP client. This argument must not be `nil`.
@return The newly-initialized HTTP client
*/
+ (instancetype)c
没有合适的资源?快使用搜索试试~ 我知道了~
猿圈APP(个人模仿版)
共753个文件
png:137个
h:110个
json:73个
5星 · 超过95%的资源 需积分: 50 35 下载量 132 浏览量
2016-03-07
11:52:37
上传
评论
收藏 20.48MB ZIP 举报
温馨提示
1、代码都是高质量代码,通过多次重构,注释非常详细 2、项目架构很清晰,无论是修改还是为以后扩展都很不错
资源推荐
资源详情
资源评论
收起资源包目录
猿圈APP(个人模仿版) (753个子文件)
01ee9dca41b6b703d070cf4a143d681f02ed27 270B
022110efef1c4a5b5a3d2357d487c3a084eee4 182B
02694d28d2d695ae5d01bb65476c92b6c43667 1KB
026a653b41e1333d848de42517981c167985ef 366B
02c5f5ce699023400393429d0423172177a6db 96B
05003097f034295e610f4d99b319b8edd68907 311B
05b247d8d4af214e71c1161d855ede6ed1e964 188B
05cc67bbf738499f2accb4b56f5f1ddc8ce444 506B
06f6fa9ed3cebaf1dce68ed506c815971ad9b9 100B
0970cb9ff1e84046dbcc87077718244179abe2 207B
09ef0f35231d102cc48be6f2bc6da1f2c4cc3a 135B
0b93980545aca7f538a42ab040f2f0d744b4d9 110B
0d111c97386211d7b024feb9cf57338b18fcdf 170B
0dc9582195e8bcfd746ca4a60d2eccb79447bc 184B
0ec8a504fbc7ab3a5d98d2ba5c8fa9027ff064 887B
0eca208c60a5cc66fcfa87dc77b44acc88894b 184B
0fc2514af65f731f5b335516bde8012c23fe77 190B
10168926590e133d143cfed4346736e159f64e 269B
112ae7aaeaf51c30173f5c7146edf07f2bc2d0 3KB
12ffa7b8a7907d406fe71eb53f2b024e280e5c 236B
134b9e657f083297a74e7bc2e81813a574d07e 163B
13ff0413dd8e9040a726a69f4ef0d1b242e94e 5KB
1450516a7813826ac005949dbed640742be428 53B
15e603a1c5ac50172b83a7af0dc1db29b36d1b 305B
16b5cf0074b62476ce544551b8998f101bf656 95B
17345403a51c08b8c52cbd4da790553193bc5b 209B
17de1600f6930ac02c84acc34b7b3125400cfd 101B
18bf23d7592be3616064178b369a53b82a5d79 100B
1c1c0e1c598d6edad1600e1f6e5bb6785960d2 737B
1ca77bdd12d375339e8e729546773ce9df1a76 108B
1d339fbe1f0b14ac2cb1962f954c2950ab0f8e 131B
1e8b701b2504e1f8581c3b79bb02aae19bb6a9 289B
1f0229c5e4d5409fe034f3f4fb9fb995e074a5 186B
1fbda0245a3db08ff9b372f354fdd0e92fa838 637B
20b71c561a3131f796bc46e1706a648c0192f0 1KB
21d2aa03df442e84b4c1ae5afa33d4d013c070 173B
21e23b80be47b1e98764e37681aab3cfcf7506 131B
21fe3fa7c1fed95363efb17c7f7ff079135003 605B
2275c41dc5006a005ad20c4a374ed718909c49 495B
22a4d815291a9518e3a5290b6d09b137a7b0df 274B
22febbac3e148cea12bfaab11e47ce1257676a 291B
23506dcfb9c4bdfa00588df841079976dd4d68 189B
2396edd5eced64ed3b49cc4717cda9a4ca7f8a 5KB
23ac8fafa0654e3dc3366c7d3a05bfdc86301d 160B
23c3e7f21f6a8b610cc083a206d1ad4e61987b 327B
2428cdf178a27a3a25f508e8fec01aff7b943e 318B
244e569241d7b23a1e0886f06b6d8718a78493 189B
2575cbe4101e0f34f8a50c3a84807a41097ca9 254B
27a91d9a3f4a84e5df53441b7d79043c4da33f 867B
290897a573705417d330a77ae48a7ba8802990 317B
2b2577d7d07bc42fe2d00d56f761dfcce2f8da 1KB
2cd31f25cfef90b58d8a37c84f70d9111e361d 256B
2cdda911c1c10e3bfea7fc1b91998058fefa60 188B
2d9570d81bf98614a284f2eef2324ed3b1e9ca 1KB
2e0e603e8ce6809a55a7b8048f2457706d7e6c 178B
2ead76073cd59c9cb37f09e5b6a3030a676b6b 185B
2ec35a8ac73d0cbd6b098ceda046a817e6054f 189B
2ee5cae746dbe4c8effe7523611b18d9339f4c 182B
2f1a1d2db45bc5c1643c666fcd55d4b55990e8 468B
30d7ab886d84834aaa0d27e58175fd4579a8a0 292B
311e6b93e5b63132754585593ecf76f7a5bbbf 2KB
31597abba1afc83706593dd87bf70a9f5a008a 156B
316600ee3212224e94f616d28d52326c8d8021 184B
3203f0d0cfba9b241faa1370cee330474f689f 184B
32134a935b6f11ba0ea7e7205b9914009d5008 1KB
3288bdbd0d7d0b7d4a054c36aa58ad71ad5164 329B
339a91c3461416cfd195733d3afa5798ead380 1KB
33d5bfb86a2aeac6a30047f82efcd141afdab9 326B
34df7489875151e456e8b59edac881b81d9679 130B
3563bd5160ccd581725f376b679573c1a2889f 189B
3727b53e4e88a9a8436f17e18169cb87c70516 540B
3789f38f2594c543f38ce688389b8f0f8023c7 646B
39af2b1a2c24df98e3cbe5a674c08c77fa28f5 434B
39d01c43800a70c9f66edfc6415dc0692efb3b 277B
3a9aae5bf467746801c8a87af07e19424d110f 184B
3d0c02ab9e6520a6ace9394882409159e8ab0f 333B
3e45dc203c81c95bbe57ddf2b315ff89c8bb6e 536B
3f33c9c4d16eebd8625dddbf41eeb223330042 231B
40ac611c377b7ef5712f41c874e321051ca090 299B
40c03b858849a1753d80a8e99cd0bbbb888ac1 2KB
43911a4efcd1906a608c97e6b0584fac6b40bd 529B
43f5e02115b458ad91057f22fc1b74a75573a8 429B
44a418e5344ae0493b77aca8a2a7805bc4a678 492B
485dfddcc719a54b25a248ec9329592032f8ed 105B
489c50497bb202cd12304ce219b4ed56a1377e 265B
49e8a4e4bc683da9f55cbfca7948c7727b00c3 114B
4a164c918651cdd1e11dca5cc62c333f097601 65B
4c22673e263e762be8631fc2aa1933f49e8a89 100B
4ceff48ef6a559fc8a5d9a02a73eed28f60b41 143B
4f247eff66dd64c2bb1bb7297a3f1327e9f087 224B
51851737e98aafd555ddc42bd07de5cc5a0a5f 288B
52f287427925d5f27d65f954b979c2ba710ca8 325B
52fbf0a4158e58ef1b2204fc72847c8e42944f 179B
5323635c4eb97c04c5de4cd9dae38dc375f4b1 254B
53a0e140cae871ecabbccc3904a0b1c4fd892b 131B
53c4cf8ec698dc166f4253286ae16b558fc114 110B
542e59b7481d73115d04647a426d9787d0ab1d 205B
542f3f7c4ac92e24b00e4614586ea313c1439d 91B
544fc98043059cb2b509da2ea8ad433f8ada6a 336B
549a8aeaf81dcd794ee3d9f9d47a85e04aadce 516B
共 753 条
- 1
- 2
- 3
- 4
- 5
- 6
- 8
资源评论
- agan114232018-02-28很好的东西 可以下载看看
nineteen_
- 粉丝: 52
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功