zoukankan      html  css  js  c++  java
  • get 和post 方式请求数据

    get 和post 方式请求数据的时候,只想说一句话,别忘了对NSMutableData *a 也就是用来接受数据的中间实例进行初始化........

    get 异步请求网络数据的步骤

      NSURL *url = [[NSURL alloc] initWithString:@"http://f.hiphotos.baidu.com/image/w%3D2048/sign=2f72d721bb12c8fcb4f3f1cdc83b9345/ac4bd11373f082020756343e49fbfbedaa641bee.jpg"];


        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:15];


        NSURLConnection *connect = [[NSURLConnection alloc] initWithRequest:request delegate:self];


        [connect release];

    - (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)respons
    {
        [self.aview setProgress:0 animated:YES];
        self.a = [respons expectedContentLength];
        [self.receiverData setLength:0];
        
    }

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
    {
        [self.receiverData appendData:data];
        float b = [self.receiverData length]/self.a;
        [self.aview setProgress:b animated:YES];
    }

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection
    {
     
        self.imageView.image  = [UIImage imageWithData:self.receiverData];
        
    }
    同步

        NSURL *url = [[NSURL alloc] initWithString:@"http://f.hiphotos.baidu.com/image/w%3D2048/sign=2f72d721bb12c8fcb4f3f1cdc83b9345/ac4bd11373f082020756343e49fbfbedaa641bee.jpg"];
        NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
        NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
        UIImage *image = [UIImage imageWithData:data];
        self.imageView.image = image;

  • 相关阅读:
    计算机漏洞安全相关的概念POC 、EXP 、VUL 、CVE 、0DAY
    开始使用kali的一些小问题:菜鸟瞎折腾
    nmap参数详解(罗列一下)
    安装kali之后必做的几件小事
    Debian下virtualBox增强功能出错
    ArcGIS Engine 基础功能(一)
    sublime 配置简单的python环境
    解决 ‘Could not fetch URL https://pypi.python.org’的问题
    golang基础语法学习
    大象盒子技术栈
  • 原文地址:https://www.cnblogs.com/xukunhenwuliao/p/3576251.html
Copyright © 2011-2022 走看看