Return to Snippet

Revision: 22745
at January 20, 2010 18:25 by tbass134


Initial Code
NSURL *url = [NSURL URLWithString:@"http://server.com/file.php"];
	
	NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url 
                                                              cachePolicy:NSURLRequestReloadIgnoringCacheData 
                                                          timeoutInterval:60];
	
	[req setHTTPMethod:@"POST"];		
	[req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
	
	NSString *postData = [NSString stringWithFormat:@"page=%@&param1=%@&param2=%@param3=%@", @"item1", @"item 2",@"item 3",@"item 4"];
	
	NSString *length = [NSString stringWithFormat:@"%d", [postData length]];	
	[req setValue:length forHTTPHeaderField:@"Content-Length"];	
	
	[req setHTTPBody:[postData dataUsingEncoding:NSASCIIStringEncoding]];
		
	NSHTTPURLResponse* urlResponse = nil;
	NSError *error = [[[NSError alloc] init] autorelease];  
	
	NSData *responseData = [NSURLConnection sendSynchronousRequest:req
												 returningResponse:&urlResponse 
															 error:&error];  
	
	NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];

Initial URL

                                

Initial Description

                                

Initial Title
NSMutableURLRequest Send Variables to Script

Initial Tags

                                

Initial Language
Objective C