Created
February 19, 2013 12:05
-
-
Save cvasilak/4985266 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.m | |
// TimeoutNSURLConnection | |
// | |
// Created by Christos Vasilakis on 2/19/13. | |
// Copyright (c) 2013 Christos Vasilakis. All rights reserved. | |
// | |
#import "ViewController.h" | |
@interface ViewController () | |
@end | |
@implementation ViewController | |
- (void)viewDidLoad | |
{ | |
[super viewDidLoad]; | |
NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:8080/RESTfulExample/services/message"]; | |
//NSURL *url = [[NSURL alloc] initWithString:@"http://localhost:8080/RESTfulExample/services/message/add"]; | |
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] | |
initWithURL:url]; | |
[req setHTTPMethod:@"GET"]; | |
/* | |
[req setHTTPMethod:@"POST"]; | |
NSString *postString = @"name=Christos"; | |
[req setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; | |
*/ | |
//[req setTimeoutInterval:2]; | |
NSURLConnection *theConnection=[[NSURLConnection alloc] | |
initWithRequest:req | |
delegate:self]; | |
} | |
- (void)didReceiveMemoryWarning | |
{ | |
[super didReceiveMemoryWarning]; | |
// Dispose of any resources that can be recreated. | |
} | |
#pragma mark - | |
#pragma mark NSURLConnection Callbacks | |
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { | |
NSLog(@"Response Code: %d\n", [(NSHTTPURLResponse *)response statusCode]); | |
NSLog(@"Content-Type: %@\n", [[(NSHTTPURLResponse *)response allHeaderFields] objectForKey:@"Content-Type"]); | |
} | |
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { | |
} | |
- (void)connection:(NSURLConnection *)connection | |
didFailWithError:(NSError *)error { | |
} | |
- (void)connectionDidFinishLoading:(NSURLConnection *)connection { | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment