·您现在的位置: 云翼网络 >> 文章中心 >> 网站建设 >> app软件开发 >> IOS开发 >> ios开发-常用网络

ios开发-常用网络

作者:佚名      IOS开发编辑:admin      更新时间:2022-07-23

直接上代码

示例:

-(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);

}];

}