原生的请求方法
2018-12-29 本文已影响7人
guoguojianshu
// 输入动态密码的请求
-(void)inputPassWord{
__weak typeof(self)weakSelf = self;
NSMutableDictionary * dict = [NSMutableDictionary dictionary];
[dictsetObject:[self.textFieldArray lastObject].text forKey:@"captcha"];
NSURLSession *session = [NSURLSession sharedSession];
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@/%@/%@/%@",OPERATOR,@"tasks",self.tokenString,@"input"]]];
request.HTTPMethod=@"post";
[requestsetValue:OPERATORAPIKEY forHTTPHeaderField:@"Authorization"];
[requestsetValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSData * data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];
request.HTTPBody= data;
NSURLSessionDataTask* dataTask = [sessiondataTaskWithRequest:requestcompletionHandler:^(NSData*_Nullabledata,NSURLResponse*_Nullableresponse,NSError*_Nullableerror) {
NSDictionary *datadict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
[weakSelftaskProcess:datadict[@"data"]];
NSLog(@"动态密码字典%@",datadict);
}];
[dataTaskresume];
}