美文网首页
原生的请求方法

原生的请求方法

作者: guoguojianshu | 来源:发表于2018-12-29 10:28 被阅读7次

    // 输入动态密码的请求

    
    -(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];
    
    }
    
    

    相关文章

      网友评论

          本文标题:原生的请求方法

          本文链接:https://www.haomeiwen.com/subject/tzlulqtx.html