Skip to content

Instantly share code, notes, and snippets.

@cvasilak
Created February 19, 2013 12:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cvasilak/4985266 to your computer and use it in GitHub Desktop.
Save cvasilak/4985266 to your computer and use it in GitHub Desktop.
//
// 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