ASIHTTPRequest load network data and upload data functions

Source: Internet
Author: User
Tags uikit

Using the ASIHTTPRequest Third library, you need to configure

Two

Upload data function using asifromdatarequest (can upload binary and string to server)

Down here, kind.

// build a project, import a third-party library, and AppDelegate.h #import <UIKit/UIKit.h>#import"ASIFormDataRequest.h"@ Interface Appdelegate:uiresponder <UIApplicationDelegate,ASIHTTPRequestDelegate>{    / / Declare the member variable of the data request    asiformdatarequest **window; @end
//code written in APPDELEGATE.M.//loading data via POST requestNsurl *url=[nsurl urlwithstring:@"http://10.0.8.8/sns/my/login.php"];//instantiate as Object_request=[[Asiformdatarequest Alloc]initwithurl:url];//Set Request Mode[_request Setrequestmethod:@"Post"];//Adding Parameters[_request Addpostvalue:@"AA_ZX"Forkey:@"username"]; [_request Addpostvalue:@"FFFF"Forkey:@"Password"];//Set proxy callbacks_request.Delegate=Self ;//Request Data[_request startasynchronous];//asynchronous requests, multithreading
#param-Mark ASIHTTPRequest-(void) requestfinished: (ASIHTTPRequest **dict=[ Nsjsonserialization  JSONObjectWithData:request.responseData options:nsjsonreadingmutablecontainers Error:nil ];   NSLog (@ "%@", Dict);} -(void) requestfailed: (ASIHTTPRequest *) request{    NSLog (@ " request failed " );}

Third, load the network data, asihttprequest (all formats of data can be loaded)

-(void) Startloadwebdata: (NSString *) strurl{//instantiating a ASIHTTPRequest objectNsurl *url=[Nsurl urlwithstring:strurl];_request=[[ASIHTTPRequest alloc]initwithurl:url];_requent.Delegate=Self ;//Start Loading Data[_requenst startasynchronous];}#pragma-mark asihttprequestdelegate//call this method when the request succeeds-(void) requestfinished: (ASIHTTPRequest *) Request{nsdictionary*dict=[Nsjsonserialization JSONObjectWithData:request.responseDataoptions:NSJSONReadingMutableContainers Error:nil ];//Agent receives data[Self.DelegateRecivedata:[dict Objectforkey:@"Application"];}//call this method when requesting network data fails-(void) requestfailed: (ASIHTTPRequest *) Request{nslog (@"failed");}

ASIHTTPRequest load network data and upload data functions

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.