标签:
1 首先引入头文件
#import "ASIFormdataRequest.h"
2 创建请求(以登录为例)
NSURL *postUrl = [NSURL URLWithString:@"YOUR URS STRING"]; NSLog(@"postUrl = %@", postUrl); ASIFormDataRequest *asiRequest = [ASIFormDataRequest requestWithURL:postUrl]; [asiRequest setUseCookiePersistence:YES]; [asiRequest setPostValue:username forKey:request_key_username]; [asiRequest setPostValue:pwd forKey:request_key_password]; [asiRequest setDelegate:self]; [asiRequest setDidFailSelector:@selector(requestFailed:)];//请求失败 [asiRequest setDidFinishSelector:@selector(requestSucceed:)];//请求成功 [asiRequest startAsynchronous];
3 请求失败响应
- (void)requestFailed:(ASIHTTPRequest *)request { NSLog(@"发送登录请求失败"); }
4 请求成功响应
- (void)requestSucceed:(ASIHTTPRequest *)request { NSLog(@"发送登录请求成功"); NSData *resultData = [request responseData]; NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:resultData options:NSJSONReadingMutableContainers error:nil]; // NSLog(@"resultDic = %@", resultDic); //TODO: 加上自己的逻辑 }
5 取消请求
if (request != nil) { [request cancel]; [request clearDelegatesAndCancel]; }
IOS 学习笔记 —— ASIHTTPRequest 之 ASIFormDataRequest
标签:
原文地址:http://my.oschina.net/bingshanguxue/blog/379941