Tag Archives: httppost

Objective-C Http request response

By | 2009-11-12 14:41:05 | 1 Comment

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);