IOS_简单get请求

//
//  PJViewController.m
//  GET
//
//  Created by pj on 14-8-3.
//  Copyright (c) 2014年 pj. All rights reserved.
//

#import "PJViewController.h"

@interface PJViewController ()

@end

@implementation PJViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self get];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)get
{
    NSString *urlString = [NSString stringWithFormat:@"http://www.baidu.com/?a=2&b=2"];
    NSURL *url = [NSURL URLWithString:urlString];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    // 在主线程上执行这条异步指令
    [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSString *result = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
        NSLog(@"success%@%@",result,[NSThread currentThread]);
    }];
    NSLog(@"end");
}

@end

 

posted @ 2014-08-03 16:36  宝贝,我永远都在  阅读(125)  评论(0)    收藏  举报