AFNetworking2.0 Simple Get,post request encapsulation and use

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.