标签:style blog http color io ar sp div c
代码:
#import <Foundation/Foundation.h> void request(NSString *urlString) { NSLog(@"BEGIN"); // make request object NSURL *url = [[NSURL alloc]initWithString:urlString]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc]initWithURL:url]; [request setHTTPMethod:@"GET"]; [request setTimeoutInterval:10]; // send request NSError *error = nil; NSHTTPURLResponse *urlResponse = nil; NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) { NSString *responseText = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding]; NSLog(@"OK"); } NSLog(@"END"); } int main(int argc, const char * argv[]) { @autoreleasepool { request(@"http://www.code-style.com"); } return 0; }
标签:style blog http color io ar sp div c
原文地址:http://www.cnblogs.com/code-style/p/4011691.html