时光

Strive to be an excellent developer

  :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::
NSString *urlString        = [NSString stringWithFormat:@"http://cnblogs.com/时光"];
// 如果url中有中文,必须encode
NSString *encodedUrlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

// 1,创建NSURL
NSURL *url                 = [NSURL URLWithString:encodedUrlString];
// 2,创建Request
NSURLRequest *request      = [NSURLRequest requestWithURL:url];
// 3,连接
// queue: 指的是Block将要执行的queue,一般都是mainQueue
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
    // 主线程,queue=[NSOperationQueue mainQueue]
    NSLog(@"%@", [NSThread currentThread]);
}];

NSLog(@"%@", urlString);
NSLog(@"%@", encodedUrlString)

2015-03-28 16:00:37.366 Demo1[1248:42662] http://cnblogs.com/时光
2015-03-28 16:00:37.367 Demo1[1248:42662] http://cnblogs.com/时光
2015-03-28 16:00:37.484 Demo1[1248:42662] <NSThread: 0x7fbb91e04b50>{number = 1, name = main}

posted on 2015-03-28 16:04  朱东方  阅读(217)  评论(0编辑  收藏  举报