ios开发-常用网络

时间:2014-10-22 23:40:50   收藏:0   阅读:619

直接上代码

示例:

-(void)touchesBeGan:(NSSet *)touches withEvent:(UIEvent *)event

{

  //1.url

  NSURL *url = [NSURL URLWithString:@"http://m.baidu.com"]‘

  //2.request

  NSURLRequest *request = [NSURLRequest requestWithURL:url];

  //3.发送网络连接 获取二进制数据

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

  //在开发http访问,通常会把返回的二进制数据变成字符串,以便于调试

  NSString *html = [NSString alloc]initWithData:data encoding:NSUTF8StringEncoding

;

  NSLog(@"%@",html);

}];

}

原文:http://www.cnblogs.com/gtbo/p/4044673.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!