IOS 学习笔记 —— ASIHTTPRequest 之 ASIFormDataRequest
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]; }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。