代码:
#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:]; // send request
NSError *error = nil;
NSHTTPURLResponse *urlResponse = nil;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error]; if ([urlResponse statusCode] >= && [urlResponse statusCode] < ) {
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 ;
}