Simple encapsulation of system network requests and network request Encapsulation

Source: Internet
Author: User

Simple encapsulation of system network requests and network request Encapsulation

AGConnectionNet
Simple encapsulation of system network requests facilitates network requests, and encapsulates data parsing and network requests in the same method for more convenient use (JSON parsing uses its own resolution method, XML parsing uses third-party ReadXML for parsing ).

Method Parameters

 

Initialization Method:
/**
* Class method: instantiate the current data request object (Singleton)
*
* @ Return current request object
*/
+ (Instancetype) shareRequestData;

 

Request data method only
/**
* Request data (session Request)
*
* @ Param URLStr URL
* @ Param parameters Request parameters
* @ Param method POST/GET (default GET request)
* @ Param success callback function for successful request
* @ Param faild callback function for request failure
*/
-(Void) requestDataURL :( NSString) URLStr parameters :( NSDictionary) parameters method :( RequestMethod) method success :( void (^) (NSData * data) success fail :( void (^) (NSError * error) fail;

 

 

Request data cut Parsing Method
/**
* Request data and parse the data
*
* @ Param URLStr URL
* @ Param parameters Request parameters
* @ Param method POST/GET (default GET request)
* @ Param format: returned data (XML/JSON)
* @ Param success callback function for successful request
* @ Param fail callback function for request failure
*/
-(Void) requestDataURL :( NSString *) URLStr parameters :( NSDictionary *) parameters method :( RequestMethod) method dataFormat :( DataFormat) format success :( void (^) (id data, NSURLResponse * response) success fail :( void (^) (NSError *) fail;

 

Source code

 

Related Article

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.