zoukankan      html  css  js  c++  java
  • NSURLConnectionDataDelegate

    #pragma mark-NSURLConnectionDataDelegate

    //收到回应

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {

        self.data = [NSMutableData data];

    }

    //接收数据

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

        [self.data appendData:data];

        

    }

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection {

        NSLog(@"%@",[NSJSONSerialization JSONObjectWithData:self.data options:NSJSONReadingMutableContainers error:nil]);

    }

    #pragma mark-NSURLConnectionDelegate

    - (BOOL)connection:(NSURLConnection *)connection canAuthenticateAgainstProtectionSpace:(NSURLProtectionSpace *)protectionSpace

    {

        NSLog(@"处理证书");

        return [protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust];

    }

    - (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge

    {

        if ([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodServerTrust]) {

            [challenge.sender useCredential:[NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust] forAuthenticationChallenge:challenge];

        } else {

            [challenge.sender cancelAuthenticationChallenge:challenge];

        }

    }

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        

        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"https://chanyouji.com/api/users.json"]];

        request.HTTPMethod = @"POST";

        //设置请求体

        request.HTTPBody = [@"email=473775989@qq.com&password=wsn13995145612"dataUsingEncoding:NSUTF8StringEncoding];

        //开启请求

        [NSURLConnection connectionWithRequest:request delegate:self];

    }

  • 相关阅读:
    【k8s】pv 处在 Terminating 状态
    【k8s】命令行自动补全
    【k8s】允许 master 节点运行 pod
    【k8s】Harbor 安装
    Nginx 允许 frame 嵌套
    Python基础教程:json中load和loads区别
    Python 基础教程:用户交互语句
    Python正则表达式-常用函数的基本使用
    Python字典循环与字典排序
    4道Python文件操作和函数练习题
  • 原文地址:https://www.cnblogs.com/wsn1993/p/5058181.html
Copyright © 2011-2022 走看看