NSURL, NSURLRequest, NSURLConnectionの基本

- (void)main
{
    NSURL * url = [[NSURL alloc] initWithString:@"http://www.yahoo.co.jp"];
    NSURLRequest * req = [[NSURLRequest alloc] initWithURL:url];
    NSURLConnection * conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];
    if(conn){
        NSLog(@"Connection Success.");
    } else {
        NSLog(@"Connection Error.");
    }
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
    NSLog(@"didReceiveData");
    NSString * receiveData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    NSLog(@"%@", receiveData);
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    NSLog(@"didReceiveResponse");
    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
    NSLog(@"%@", [httpResponse allHeaderFields] );
}

NSURLにURLを投げて、NSURLRequestでリクエストオブジェクトを作って、NSURLConnectionでhttpコネクションを起こします。delegateしたクラスでデータを受け取ります。NSData, NSURLResponseでデータを受け取ります。