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

댓글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다