The ASIHttpRequest function is used to load network data and data.

Source: Internet
Author: User

The ASIHttpRequest function is used to load network data and data.

To use the third library of ASIHttpRequest, You need to configure

II,

The data upload function uses ASIFromDataRequest (binary and string can be uploaded to the server)

The following is a test

// Create a project and import it to a third-party library in AppDelegate. h # import <UIKit/UIKit. h> # import "ASIFormDataRequest. h "@ interface AppDelegate: UIResponder <UIApplicationDelegate, ASIHTTPRequestDelegate >{// declare the data request member variable ASIFormDataRequest * _ request ;}@ property (strong, nonatomic) UIWindow * window; @ end
// In AppDelegate. code written in m // load data through the POST request NSURL * url = [NSURL URLWithString: @ "http: // 10.0.8.8/sns/my/login. php "]; // instance into object _ request = [[ASIFormDataRequest alloc] initWithURL: url]; // set the request method [_ request setRequestMethod: @" post "]; // Add the parameter [_ request addPostValue: @ "aa_Zx" forKey: @ "username"]; [_ request addPostValue: @ "ffff" forKey: @ "password"]; // sets proxy callback _ request. delegate = self; // request data [_ request startAsynchronous]; // asynchronous request, multithreading
# Param-mark ASIHttpRequest-(void) requestFinished :( ASIHTTPRequest *) request {NSDictionary * dict = [NSJSONSerialization JSONObjectWithData: request. responseData options: NSJSONReadingMutableContainers error: nil]; NSLog (@ "% @", dict) ;}- (void) requestFailed :( ASIHTTPRequest *) request {NSLog (@ "request failed ");}

3. Attach network data and ASIHttpRequest (data in all formats can be loaded)

-(Void) startLoadWebData :( NSString *) strURL {// instantiate ASIHttpRequest object NSURL * url = [NSURL URLWithString: strURL]; _ request = [[ASIHTTPRequest alloc] initWithURL: url]; _ requent. delegate = self; // start to load data [_ requenst startAsynchronous];} # Call this method when pragma-mark ASIHttpRequestDelegate // when the request is successful-(void) requestFinished :( ASIHTTPRequest *) request {NSDictionary * dict = [NSJSONSerialization JSONObjectWithData: request. responseDataoptions: NSJSONReadingMutableContainers error: nil]; // The proxy receives data [self. delegate reciveData: [dict objectForKey: @ "application"];} // call this method when network data fails to be requested-(void) requestFailed :( ASIHTTPRequest *) request {NSLog (@ "failed ");}

 

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.