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:@"https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiF-ni6oLp-GJGWO1KOo5RJsMkvorerlMlyDz-p4oFa9MwEz5_MNRaiI87yt0DnVG0sXi-iKV1G-wWoA8P2h5qMp9wsQj0JnFaNI1shr_nzuF54rhRuLM2fd3So3LkYsUeCNT2KcS7kspPn/s220-h/Photo+on+2011-06-29+at+08.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];