• 网络请求代理方式


    #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中内容观察者的使用 ContentObserver类详解 (转)
    Spinner
    对话框
    ButtonBar 的使用
    EditText/RadioButton/CheckBox使用
    ListView
    PieChar,此代码参考网上
    ComboBox中使用事件
    ColorPicker
    Button
  • 原文地址:https://www.cnblogs.com/lhp-1992/p/4664929.html
Copyright © 2020-2023  润新知