下面是内存溢出 jb51.cc 通过网络收集整理的代码片段。
内存溢出小编现在分享给大家,也给大家做个参考。
//初始化一个请求对象 AFhttpRequestoperationManager *manager = [AFhttpRequestoperationManager manager]; Nsstring * url = @"你的请求地址"; //dic 为参数字典 [manager POST:url parameters:dic success:^(AFhttpRequestoperation *operation, ID responSEObject) { //请求成功的回调 } failure:^(AFhttpRequestoperation *operation, NSError *error) { //请求失败的回调 }];
AFhttpRequestoperationManager *manager = [AFhttpRequestoperationManager manager]; Nsstring * url = @"你的请求地址"; [manager GET:url parameters:nil success:^(AFhttpRequestoperation *operation, NSError *error) { //请求失败的回调 }];
[AFhttpRequestoperationManager manager]
+ (instancetype)manager { return [[self alloc] initWithBaseURL:nil];}
success:^(AFhttpRequestoperation *operation, ID responSEObject)
@interface AFhttpRequestoperation : AFURLConnectionoperation@property (Readonly, nonatomic, strong) NShttpURLResponse *response;@property (nonatomic, strong) AFhttpResponseSerializer <AFURLResponseSerialization> * responseSerializer;@property (Readonly, strong) ID responSEObject;@end
@interface AFURLConnectionoperation : NSOperation <NSURLConnectionDelegate, NSURLConnectionDataDelegate, NSSecureCoding, NScopying>@property (nonatomic, strong) NSSet *runLoopModes;@property (Readonly, strong) NSURLRequest *request;@property (Readonly, strong) NSURLResponse *response;@property (Readonly, strong) NSError *error;@property (Readonly, strong) NSData *responseData;@property (Readonly, copy) Nsstring *responseString;@property (Readonly, assign) nsstringencoding responseStringEnCoding;@property (nonatomic, assign) BOol shouldUseCredentialStorage;@property (nonatomic, strong) NSURLCredential *credential;@property (nonatomic, strong) AFSecurityPolicy *securityPolicy;@property (nonatomic, strong) NSinputStream *inputStream;@property (nonatomic, strong) NSOutputStream *outputStream;@property (nonatomic, strong) dispatch_queue_t completionQueue;@property (nonatomic, strong) dispatch_group_t completionGroup;@property (nonatomic, strong) NSDictionary *userInfo;- (instancetype)initWithRequest:(NSURLRequest *)urlRequest NS_DESIGNATED_INITIAliZER;- (voID)pause;- (BOol)isPaused;- (voID)resume;
responseString
NSLog ( @"operation: %@" , operation. responseString );
url = [url stringByAddingPercentEscapesUsingEnCoding:NSUTF8StringEnCoding];
//为这个下载任务http头添加@"User-Agent"字段 [manager.requestSerializer setValue:_scrData forhttpheaderFIEld:@"User-Agent"]; //打印头信息 NSLog(@"%@",manager.requestSerializer.httpRequestheaders);
[manager GET:url parameters:nil success:^(AFhttpRequestoperation *operation, ID responSEObject) { //写缓存 Nsstring *cachePath = @"你的缓存路径";// /library/Caches/MyCache [data writetofile:cachePath atomically:YES]; succsee(data); } failure:^(AFhttpRequestoperation *operation, NSError *error) { }];
Nsstring * cachePath = @"你的缓存路径"; if ([[NSfileManager defaultManager] fileExistsAtPath:cachePath]) { //从本地读缓存文件 NSData *data = [NSData dataWithContentsOffile:cachePath]; }
//初始化一个下载请求数组NSArray * requestArray=[[NSMutableArray alloc]init];//每次开始下载任务前做如下判断for (Nsstring * request in requestArray) { if ([url isEqualToString:request]) { return; } } [requestArray addobject:url]; //下载成功或失败后 [manager GET:url parameters:nil success:^(AFhttpRequestoperation *operation, ID responSEObject) { [requestArray removeObject:url] } failure:^(AFhttpRequestoperation *operation, NSError *error) { [requestArray removeObject:url] }];
以上是内存溢出(jb51.cc)为你收集整理的全部代码内容,希望文章能够帮你解决所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
总结以上是内存溢出为你收集整理的AFNetWorking用法及缓存处理全部内容,希望文章能够帮你解决AFNetWorking用法及缓存处理所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)