// AFHTTPClient.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 "AFURLConnectionOperation.h"
#import <Availability.h>
/**
`AFHTTPClient` 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 `AFHTTPClient` 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 `AFHTTPClient` 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 `AFHTTPClient` subclass, override `requestWithMethod:path:parameters`.
To change the behavior of all request operation construction for an `AFHTTPClient` subclass, override `HTTPRequestOperationWithRequest:success:failure`.
## Default Headers
By default, `AFHTTPClient` 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
`AFHTTPClient` 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 {
AFNetworkReachabilityStatusUnknown = -1,
AFNetworkReachabilityStatusNotReachable = 0,
AFNetworkReachabilityStatusReachableViaWWAN = 1,
AFNetworkReachabilityStatusReachableViaWiFi = 2,
} AFNetworkReachabilityStatus;
#else
#pragma message("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
#pragma message("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
#pragma message("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 {
AFFormURLParameterEncoding,
AFJSONParameterEncoding,
AFPropertyListParameterEncoding,
} AFHTTPClientParameterEncoding;
@class AFHTTPRequestOperation;
@protocol AFMultipartFormData;
@interface AFHTTPClient : 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, strong) NSURL *baseURL;
/**
The string encoding used in constructing url requests. This is `NSUTF8StringEncoding` by default.
*/
@property (nonatomic, assign) NSStringEncoding stringEncoding;
/**
The `AFHTTPClientParameterEncoding` value corresponding to how parameters are encoded into a request body. This is `AFFormURLParameterEncoding` 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 `AFJSONParameterEncoding`, is used when posting complicated or nondeterministic parameter structures.
*/
@property (nonatomic, assign) AFHTTPClientParameterEncoding parameterEncoding;
/**
The operation queue which manages operations enqueued by the HTTP client.
*/
@property (readonly, nonatomic, strong) NSOperationQueue *operationQueue;
/**
The reachability status from the device to the current `baseURL` of the `AFHTTPClient`.
@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) AFNetworkReachabilityStatus networkReachabilityStatus;
#endif
/**
Default SSL pinning mode for each `AFHTTPRequestOperation` created by `HTTPRequestOperationWithRequest:success:failure:`.
*/
#ifdef _AFNETWORKING_PIN_SSL_CERTIFICATES_
@property (nonatomic, assign) AFURLConnectionOperationSSLPinningMode defaultSSLPinningMode;
#endif
/**
Whether each `AFHTTPRequestOperation` created by `HTTPRequestOperationWithRequest:success:failure:` should accept an invalid SSL certificate.
If `_AFNETWORKING_ALLOW_INV
没有合适的资源?快使用搜索试试~ 我知道了~
iOS异步加载图片 (需要至少12个字的名称,过分!)
共82个文件
h:32个
m:27个
png:5个
需积分: 0 70 下载量 117 浏览量
2013-05-16
17:13:03
上传
评论
收藏 255KB ZIP 举报
温馨提示
异步加载图片,之前的版本发现还是有问题,这次做了修改.上次忘记初始化,犯一低级错误。不好意思
资源推荐
资源详情
资源评论
收起资源包目录
XMLPractice 2.zip (82个子文件)
XMLPractice
XMLPractice.xcodeproj
project.xcworkspace
contents.xcworkspacedata 156B
xcuserdata
kzxd.xcuserdatad
UserInterfaceState.xcuserstate 37KB
xcuserdata
kzxd.xcuserdatad
xcdebugger
Breakpoints.xcbkptlist 2KB
xcschemes
xcschememanagement.plist 483B
XMLPractice.xcscheme 3KB
project.pbxproj 37KB
.DS_Store 6KB
XMLPractice
avatar_noimg.jpg 2KB
ViewController.m 10KB
.DS_Store 6KB
XMLPractice-Prefix.pch 641B
en.lproj
ViewController.xib 12KB
InfoPlist.strings 45B
main.m 332B
XMLPractice-Info.plist 1KB
Tweet.h 1KB
avatar_loading.jpg 2KB
ImgRecord.m 309B
Third-Party
AFOSCClient.h 263B
TBXML
TBXML-Support
TBXML-Prefix.pch 1KB
TBXML-iOS-Prefix.pch 159B
TBXML-Headers
TBXML.h 9KB
TBXML+Compression.h 3KB
TBXML+HTTP.h 963B
TBXML-Code
TBXML+HTTP.m 3KB
TBXML+Compression.m 9KB
TBXML.m 31KB
.DS_Store 6KB
IconDownloader
IconDownloader.m 6KB
IconDownloader.h 3KB
AFOSCClient.m 1KB
Cache
TQImageCache.h 802B
TQImageCache.m 5KB
ASIHttp
ASINetworkQueue.m 10KB
ASIHTTPRequestDelegate.h 1KB
Reachability.h 7KB
.DS_Store 12KB
ASIHttpHeaders.h 444B
ASIHTTPRequest.m 153KB
ASICacheDelegate.h 2KB
ASIInputStream.m 3KB
ASIAuthenticationDialog.h 1KB
ASIDownloadCache.h 2KB
ASIFormDataRequest.m 11KB
ASIFormDataRequest.h 3KB
ASIProgressDelegate.h 2KB
ASIHTTPRequestConfig.h 944B
ASIInputStream.h 969B
ASIAuthenticationDialog.m 15KB
Reachability.m 23KB
ASINetworkQueue.h 4KB
ASIDownloadCache.m 14KB
ASIHTTPRequest.h 37KB
AFNetworking
AFHTTPClient.m 52KB
AFXMLRequestOperation.h 5KB
AFHTTPRequestOperation.h 6KB
AFNetworking.h 2KB
AFURLConnectionOperation.m 31KB
UIImageView+AFNetworking.m 6KB
AFPropertyListRequestOperation.m 6KB
AFHTTPClient.h 37KB
AFXMLRequestOperation.m 6KB
AFImageRequestOperation.h 6KB
AFNetworkActivityIndicatorManager.m 5KB
AFJSONRequestOperation.h 4KB
AFJSONRequestOperation.m 6KB
AFPropertyListRequestOperation.h 3KB
AFNetworkActivityIndicatorManager.h 4KB
AFImageRequestOperation.m 9KB
AFURLConnectionOperation.h 20KB
UIImageView+AFNetworking.h 5KB
AFHTTPRequestOperation.m 13KB
big_avatar.png 3KB
ImgRecord.h 288B
Default-568h@2x.png 18KB
ViewController.h 605B
AppDelegate.h 360B
big_avatar_loading.png 6KB
Default.png 6KB
Tweet.m 2KB
Default@2x.png 16KB
AppDelegate.m 2KB
共 82 条
- 1
资源评论
悠悠悠哉e
- 粉丝: 21
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功