Objective-C Http request response

By | 2009년 11월 12일

	NSURL *url = [NSURL URLWithString:@"https://www.google.com/accounts/ClientLogin"];
	
	NSMutableURLRequest *loginRequest = [NSMutableURLRequest requestWithURL:url];
	
	[loginRequest setHTTPMethod:@"POST"];
		
	[loginRequest addValue:@"Content-Type" forHTTPHeaderField:@"application/x-www-form-urlencoded"];
	
	[loginRequest addValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
	
	NSString *requestBody = [[NSString alloc]
							 
							 initWithFormat:@"Email=%@&Passwd=%@&service=finance&source=%@",
							 
							 @"mars", @"1234", [NSString stringWithFormat:@"%@%d", @"ashlux-igFinance-1.0"]];
	
	[loginRequest setHTTPBody:[requestBody dataUsingEncoding:NSASCIIStringEncoding]];	
	
	NSHTTPURLResponse *response = NULL;
	
	NSData *responseData = [NSURLConnection sendSynchronousRequest:loginRequest returningResponse:&response error:nil];
	
	NSString *responseDataString = [[NSString alloc] initWithData:responseData encoding:NSASCIIStringEncoding];
	
	NSLog(@"Response from Google: %@", responseDataString);

One thought on “Objective-C Http request response

Comments are closed.