AFNetworking2.0 Simple Get,post request encapsulation and use
Afnetworking don't need me to repeat its strong, I just do a very simple package, solve the problem of sometimes request error, provide source code to everyone.
Package Source Library:
Http://pan.baidu.com/s/1wDLIQ
Source:
Networking.h and NETWORKING.M
////Networking.h//Weather////Created by youxianming on 15/01/01.//Copyright (c) 2014 youxianming. All rights reserved.//#import<Foundation/Foundation.h>#import "AFNetworking.h"@interfaceNetworking:nsobject#pragmaMark-get Request + (void) GET: (NSString *) urlstring parameters: (ID) Parameters success: (void(^) (Afhttprequestoperation *operation,IDresponseobject)) Success Failure: (void(^) (Afhttprequestoperation *operation, Nserror *error)) Failure;#pragmaMark-post Request + (void) POST: (NSString *) urlstring parameters: (ID) Parameters success: (void(^) (Afhttprequestoperation *operation,IDresponseobject)) Success Failure: (void(^) (Afhttprequestoperation *operation, Nserror *error)) Failure;@end
////NETWORKING.M//Weather////Created by youxianming on 15/01/01.//Copyright (c) 2014 youxianming. All rights reserved.//#import "Networking.h"@implementationNetworking+ (void) GET: (NSString *) urlstring parameters: (ID) Parameters success: (void(^) (Afhttprequestoperation *operation,IDresponseobject)) Success Failure: (void(^) (Afhttprequestoperation *operation, Nserror *error)) Failure {Afhttprequestoperationmanager*manager =[Afhttprequestoperationmanager Manager]; //prevent it from being resolvedManager.responseSerializer.acceptableContentTypes =[manager.responseSerializer.acceptableContentTypes setbyaddingobject:@"text/html"]; [Manager get:urlstring parameters:parameters success:^ (Afhttprequestoperation *operation,IDresponseobject) { if(Success) {success (operation, Responseobject); }} failure:^ (Afhttprequestoperation *operation, Nserror *error) { if(failure) {failure (operation, error); } }];}+ (void) POST: (NSString *) urlstring parameters: (ID) Parameters success: (void(^) (Afhttprequestoperation *operation,IDresponseobject)) Success Failure: (void(^) (Afhttprequestoperation *operation, Nserror *error)) Failure {Afhttprequestoperationmanager*manager =[Afhttprequestoperationmanager Manager]; //prevent it from being resolvedManager.responseSerializer.acceptableContentTypes =[manager.responseSerializer.acceptableContentTypes setbyaddingobject:@"text/html"]; [Manager post:urlstring parameters:parameters success:^ (Afhttprequestoperation *operation,IDresponseobject) { if(Success) {success (operation, Responseobject); }} failure:^ (Afhttprequestoperation *operation, Nserror *error) { if(failure) {failure (operation, error); } }];}@end
Get request conversion with parameter and without parameter:
POST request:
Source code Modification of the place:
AFNetworking2.0 Simple Get,post request encapsulation and use