zoukankan      html  css  js  c++  java
  • iOS之数据请求NSURLConnection

    iOS之数据请求NSURLConnection


     NSString *lcsUrl = @"http://192.168.1.1:8080/lcsUrl";

        

        //假设网址中有汉字。须要先转码

        NSString *word = [NSString stringWithUTF8String:"汉字"];//注意此处到字符串要求传一个c的字符串。没有@

        

        NSString *finaUrl = [NSString stringWithFormat:@"http://192.168.1.1:8080/lcsUrl= %@",word];

        

        NSURL *url = [NSURL URLWithString:lcsUrl];

        NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];

        request.HTTPMethod = @"GET";

        request.timeoutInterval = 60;

        NSURLConnection *connection = [NSURLConnection connectionWithRequest:request delegate:self];

        [connection start];

    请求出错

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

    {

        NSLog(@"请求出错");

    }


    请求中接收到数据

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

    {

        [_data appendData:data];

    }

    请求完成

    - (void)connectionDidFinishLoading:(NSURLConnection *)connection

    {

        NSString *str = [[NSString alloc] initWithData:_data encoding:NSUTF8StringEncoding];

        //在这里处理你收到的数据

    }



  • 相关阅读:
    elk 分布式数据同步
    mget 同时获取
    Jzoj1460 无题noname
    Jzoj1460 无题noname
    Jzoj1322硬币
    Jzoj1322硬币
    Jzoj1321 灯
    Jzoj1321 灯
    Jzoj1310 生日礼物
    Jzoj1310 生日礼物
  • 原文地址:https://www.cnblogs.com/yutingliuyl/p/7061201.html
Copyright © 2011-2022 走看看