IOS接口解析(GET请求)
1、声明一个afManager
@property (nonatomic,strong) AFHTTPRequestOperationManager *afManager;
2、在ViewDidLoad里面初始化
//初始化afManager
self.afManager = [AFHTTPRequestOperationManager manager];
// 设置返回格式-二进制格式
[ self.afManager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
3、设置请求所需的参数
NSDictionary *userDict = [NSDictionary dictionaryWithObjectsAndKeys:self.phoneNumber.text,@"cMob", nil];
// NSDictionary *userDict = @{@"cMob":self.phoneNumber.text};
NSLog(@"验证码URL-->%@",Identify_URL);
NSLog(@"参数userDict-->%@",userDict);
4、开始请求接口
[self.afManager GET:Identify_URL parameters:userDict success:^(AFHTTPRequestOperation *operation, id responseObject) {
//解析服务端返回的json格式数据
NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:0 error:nil];
NSLog(@"验证码URL-->%@,返回值dict-->%@",Identify_URL,dict);
if ([dict[@"result"] isEqualToString:@"0"]) {
for (NSDictionary *infoDict in dict[@"datas"]) {
//存储验证码
_vCode = infoDict[@"code"];
}
}
else
{
[self custemAlertProm:dict[@"information"]];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"%@..",error);
[self custemAlertProm:@"请检查网络"];
}];