Return to Snippet

Revision: 61619
at December 29, 2012 02:04 by ryantxr


Initial Code
// Quick synchronous URL request 
NSURL *url = [NSURL URLWithString:@"http://some-internet-place"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSURLResponse *response;
NSError *error;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// need to check for errors, like if it was a bad call there will be no responsestring
// but your error will have some data
if(!error)
{
	NSLog(@"response = %@", responseString);

	// Take all data and split into array by comma
	NSArray* mountArray = [responseString componentsSeparatedByString: @","];
	// Just a test var called testItem at the index of 10
	NSString* testItem = [mountArray objectAtIndex: 10];
	NSLog(@"test item at 10 = %@", testItem);
}
// Authors:
// Sam Walton
// Ethan Irish
// www.seven-labs.com
// Be kind & share :)

Initial URL


Initial Description
Simple synchronous web request for ios.
// Credit to the original authors:
// Sam Walton
// Ethan Irish
// www.seven-labs.com
// Be kind & share :)

Initial Title
simple ios url request

Initial Tags
iphone

Initial Language
iPhone