zoukankan      html  css  js  c++  java
  • 网络请求代理方式

    #pragma mark-------网络请求代理方式

     

    - (IBAction)DelegateButton:(UIButton *)sender {

        

        NSString *urlString = @"http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx?date=20131129&startRecord=1&len=5&udid=1234567890&terminalType=Iphone&cid=213";

        NSURL *url = [NSURL URLWithString:urlString];

        

        NSURLRequest *request = [NSURLRequest requestWithURL:url];

        //请求数据代理回调的方式

        [NSURLConnection connectionWithRequest:request delegate:self];

    }

     

    //客户端收到服务器响应

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

    {

        //初始化receiveData 对象

        self.receiveData = [NSMutableData data];

    }

     

    //收到数据

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

    {

        //拼接数据

        [self.receiveData appendData:data];

    }

     

    //介绍数据完毕

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection

    {

    //    解析数据

        NSDictionary *dict =[NSJSONSerialization JSONObjectWithData:self.receiveData options:NSJSONReadingMutableContainers error:nil];

        NSLog(@"%@", dict);

        

    }

     

    //网络请求失败的时候

    - (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error

    {

        NSLog(@"%@", error);

    }

     

  • 相关阅读:
    Android Studio相关
    iOS自动签名网站
    Ruby开发小记
    Python全栈之路目录结构
    不会docker的开发
    Centos7安装python3
    03 centos7的基本价绍
    02 centos虚拟机安装
    01 Linux虚拟机的安装
    跨域问题的解决
  • 原文地址:https://www.cnblogs.com/lhp-1992/p/4664929.html
Copyright © 2011-2022 走看看