zoukankan      html  css  js  c++  java
  • IOS 网络解析

    网络解析同步异步

    /*------------------------get同步-------------------------------------*/

    - (IBAction)GET_TB:(id)sender

    {

        //1.创建url

        NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];

        //2.创建一个请求对象

        NSMutableURLRequest *requst = [NSMutableURLRequest requestWithURL:url];

        //请求方式

        [requst setHTTPMethod:@"get"];

        NSURLResponse *response = nil;

        NSError *err= nil;

        //3.建立连接

        NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:&response error:&err];

        NSLog(@"%@",data);

        NSLog(@"同步");


        

    }

    /*---------------------------get异步------------------------------------*/


    - (IBAction)GET_YB:(id)sender

    {

        //1.创建url

        NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];

        //2.创建请求对象

        NSURLRequest *requset = [NSURLRequest requestWithURL:url];

        //3.建立连接

        [NSURLConnection sendAsynchronousRequest:requset queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

            NSLog(@"%@",data);

        }];

        NSLog(@"异步");

    }


    /*------------------------------post同步------------------------------------------*/


    - (IBAction)POST_TB:(id)sender

    {

        //1.创建URL

        NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];

        //2.创建请求对象

        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

        [request setHTTPMethod:@"post"];

        //3.加入包体

        NSString *str =@"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";

        //将字符串转换成NSDATA格式

        NSData *dataBody = [str dataUsingEncoding:NSUTF8StringEncoding];

        //4.给请求设body

        [request setHTTPBody:dataBody];

        //5.创建连接

        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

        NSLog(@"%@",data);

        NSLog(@"POST同步");

        

    }

    /*------------------------------post异步------------------------------------------*/


    - (IBAction)POST_YB:(id)sender

    {

        //1.创建URL

        NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];

        //2.创建请求对象

        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];

        [request setHTTPMethod:@"post"];

        //3.给请求对象加入body

        NSString *bodyStr = @"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";

        NSData *dataBody = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];

        [request setHTTPBody:dataBody];

        //4.创建连接

        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

            NSLog(@"%@",data);

        }];

        NSLog(@"POST异步");

    }

    /*------------------------get同步-------------------------------------*/
    - (IBAction)GET_TB:(id)sender
    {
        //1.创建url
        NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];
        //2.创建一个请求对象
        NSMutableURLRequest *requst = [NSMutableURLRequest requestWithURL:url];
        //请求方式
        [requst setHTTPMethod:@"get"];
        NSURLResponse *response = nil;
        NSError *err= nil;
        //3.建立连接
        NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:&response error:&err];
        NSLog(@"%@",data);
        NSLog(@"同步");
    
        
    }
    /*---------------------------get异步------------------------------------*/
    
    - (IBAction)GET_YB:(id)sender
    {
        //1.创建url
        NSURL *url = [NSURL URLWithString:@"http://project.lanou3g.com/teacher/yihuiyun/lanouproject/activitylist.php"];
        //2.创建请求对象
        NSURLRequest *requset = [NSURLRequest requestWithURL:url];
        //3.建立连接
        [NSURLConnection sendAsynchronousRequest:requset queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            NSLog(@"%@",data);
        }];
        NSLog(@"异步");
    }
    
    /*------------------------------post同步------------------------------------------*/
    
    - (IBAction)POST_TB:(id)sender
    {
        //1.创建URL
        NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];
        //2.创建请求对象
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [request setHTTPMethod:@"post"];
        //3.加入包体
        NSString *str =@"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";
        //将字符串转换成NSDATA格式
        NSData *dataBody = [str dataUsingEncoding:NSUTF8StringEncoding];
        //4.给请求设body
        [request setHTTPBody:dataBody];
        //5.创建连接
        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        NSLog(@"%@",data);
        NSLog(@"POST同步");
        
    }
    /*------------------------------post异步------------------------------------------*/
    
    - (IBAction)POST_YB:(id)sender
    {
        //1.创建URL
        NSURL *url = [NSURL URLWithString:@"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx"];
        //2.创建请求对象
        NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
        [request setHTTPMethod:@"post"];
        //3.给请求对象加入body
        NSString *bodyStr = @"date=20131129&startRecord=5&len=5&udid=1234567890&terminalType=Iphone&cid=215";
        NSData *dataBody = [bodyStr dataUsingEncoding:NSUTF8StringEncoding];
        [request setHTTPBody:dataBody];
        //4.创建连接
        [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
            NSLog(@"%@",data);
        }];
        NSLog(@"POST异步");
    }
    


  • 相关阅读:
    Python-爬虫-解析库(pyquery)的使用
    Python-爬虫-解析库(Beautiful Soup)的使用
    Python-爬虫-基本库(requests)使用-抓取猫眼电影Too100榜
    Python-爬虫-基本库(requests)使用
    Go基础及语法(五)
    Go基础及语法(四)
    Go基础及语法(三)
    Go基础及语法(二)
    Go基础及语法(一)
    MySQL8.0随笔整理
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/6784580.html
Copyright © 2011-2022 走看看