NSMutableURLrequest with POST data





URL request with POST data example





NSString *post = @"username=stalin&password=stalin123";
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding                            allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[[NSMutableURLRequest allocinitautorelease];
[request setURL:[NSURL URLWithString:@"http://3.bp.blogspot.com/-qhm0SeQ7bFo/TgqeqMI-wKI/AAAAAAAABYI/-r7ZKcmbjMA/s220-h/Photo%2Bon%2B2011-06-29%2Bat%2B08.21.jpg"]];

[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *err;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];