Leaks in NSURLConnection - ios

I have googled a lot and read a lot about the leaks issue with NSURLConnection, but none of them gives a definite answer as to what is the solution to overcome these leaks.
I create an asynchronous connection and every time the connection is established, I get a GeneralBlock-3584 leak. Sometimes the responsible library is shown to be Foundation [NSThread start] frame. Some instances of GeneralBlock-3584 have CFNetwork HostLookup_Master::HostLookup_Master(__CFString const*, InheritEnum<_ExtendedHostInfoType, CFHostInfoType>, __CFHost*, CFStreamError*) as responsible frame.
I tried setting NSURLCache size to 0 as suggested by some. Howvever, even that doesn't work.
Here is what my connector class looks like:
-(void) connectToUrl:(NSString*)urlStr withDelegate:(id)theDelegate{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:urlStr];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"GET"];
[request setValue:#"application/xml" forHTTPHeaderField:#"Content-Type"];
self.delegate = theDelegate;
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[NSURLConnection connectionWithRequest:request delegate:self];
[pool release];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data{
if(xmlResponse == nil){
xmlResponse = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
}
else{
NSMutableString *temp = [[NSMutableString alloc] initWithData:data encoding:NSISOLatin1StringEncoding];
[xmlResponse appendString:temp];
[temp release];
}
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection{
[[NSURLCache sharedURLCache] setMemoryCapacity:0];
[[NSURLCache sharedURLCache] setDiskCapacity:0];
[self.delegate connectionDidFinish:self];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{
[self.delegate connectionDidFail:self];
}
And I am calling this connector class's connectToUrl:(NSString*)urlStr withDelegate:(id)theDelegate method as below:
Connector *con = [[Connector alloc] init];
[con connectToUrl:urlStr withDelegate:self];
I am releasing 'con' in connectionDidFinish and connectionDidFail methods of delegate class.
Please suggest a solution for the GeneralBlock-3584 leaks. I have been racking my brains for long.

The leaks have gone away since iOS4.

Related

NSUrlConnection Delegate methods are not getting called from helper class

I have to do SSL pinning so need to verify server side SSL certificate.
SO I have to use NSURL delegates. I have a helper class in which I have created method which returns me login response:
- (NSData *)sendSynchronousRequest:(NSString *)strNewLoginRequest
returningResponse:(NSURLResponse **)response
error:(NSError **)error {
NSMutableURLRequest *finalRequest = nil;
NSURL *url= [NSURL URLWithString:const_url];
finalRequest = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:30.0];
NSData *requestData = [NSData dataWithBytes:[strLoginRequest UTF8String] length:[strLoginRequest length]];
self.connection = [[NSURLConnection alloc] initWithRequest:finalRequest delegate:self startImmediately:NO];
NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop];
[self.connection unscheduleFromRunLoop:currentRunLoop forMode:NSDefaultRunLoopMode];
[self.connection scheduleInRunLoop:currentRunLoop forMode:#"connectionRunLoopMode"];
[self.connection start];
while ([currentRunLoop runMode:#"connectionRunLoopMode" beforeDate:[NSDate distantFuture]]);
return self.mutableResponse;
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.response = response;
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
self.mutableResponse = [[NSMutableData alloc]init];
[self.mutableResponse appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
dispatch_async(dispatch_get_main_queue(), ^{
if (loadingView)
{
[loadingView removeView];
}
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Failure" message:#"Network Failure" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
});
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
if (loadingView)
{
[loadingView removeView];
}
self.resultString = [[NSString alloc] initWithData:self.mutableResponse encoding:NSASCIIStringEncoding];
}
and I am calling this method from another class called ViewController with code
-(void)doLogin
{
self.service = [[SyncCommunicationService alloc]init];
NSData *data = [self.service sendSynchronousRequest:strNewLoginRequest
returningResponse:&response
error:nil];
}
I have tried calling this method in background and on main thread but still delegate methods are not getting called, I have tried many other answers from same website but still couldn't able to solve this issue so please can anybody have a clue what am I doing wrong.
I'm wondering why would anyone use asynchronous request for performing task synchronously? Not to mention this strange way to wait with while statement instead of dispatch_semaphore or something similar.
However, why You even bother with delegate? Just use class method sendSynchronousRequest:returningResponse:error:. I think, it would suffice in your case

NSURLConnection delegate methods are not being called

I am trying to download a set of files from a web server using NSURLConnection but at the point the connection appears to be made, the connection's delegate methods never get fired and so the file never gets downloaded. I have read many answers on SO and other sources and have tried the fixes that have been advised but to no avail, which makes me think I have made a different mistake here.
I have a viewController (InitViewController.m) which loads another class's method:
GetData *getDataInstance = [[GetData alloc] init];
[getDataInstance startUpdate];
GetData.m then does some checking and runs the class in charge of getting the files:
GetFiles *getFilesInstance = [[GetFiles alloc] init];
[getFilesInstance doFilesNeedDownloading];
doFilesNeedDowngoading method checks to see if we need the file and then runs getFiles:
-(void)getFile//:(NSString *) fullURL
{
// I have checked if the connection is run on the main thread and it is
NSLog(#"Is%# main thread", ([NSThread isMainThread] ? #"" : #" NOT"));
NSURL *downloadURL = [NSURL URLWithString:fullURL];
NSMutableURLRequest *dlRequest = [NSMutableURLRequest requestWithURL:downloadURL];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:dlRequest delegate:self];
[theConnection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[theConnection start];
if(theConnection) { //me checking for connection which is 'true'
NSLog(#"Connection for %# worked", fullURL);
} else {
NSLog(#"Connection for %# failed", fullURL);
}
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
responseData = [[NSMutableData alloc] init];
NSString *fileName = [[NSURL URLWithString:fullURL] lastPathComponent];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:fileName];
[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
file = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[file seekToEndOfFile];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
[file seekToEndOfFile];
[file writeData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[file closeFile];
}
I did originally fire the getDataInstance startUpdate in a separate thread in an update to have the 'getting data' part of the app separate to the 'UI building' part of the app and thought this might be the issue but for now I have remove that and even put in'[theConnection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode]' as per other answers to this kind of question on SO.
I'm sure there will be something really obvious that I have missed, any ideas?
Thanks,
EDIT
I have now tried this code again but in the initViewController so this is pretty much the first thing that is fired when the app loads. This is no longer in another class or thread etc.:
-(void)getFile
{
fullURL = #"http://myURL.com/terms-and-conditions.txt";
NSURL *downloadURL = [NSURL URLWithString:fullURL];
NSMutableURLRequest *dlRequest = [NSMutableURLRequest requestWithURL:downloadURL];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:dlRequest delegate:self];
[theConnection start];
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
responseData = [[NSMutableData alloc] init];
NSString *fileName = [[NSURL URLWithString:fullURL] lastPathComponent];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentationDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:fileName];
[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
file = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
[file seekToEndOfFile];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[responseData appendData:data];
[file seekToEndOfFile];
[file writeData:data];
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection {
[file closeFile];
}
getFile gets fired but it's delegate methods still don't get fired?
If you create NSURLConnection in other thread you have to manually start the run loop.
Try with this:
-(void)getFile
{
NSURL *downloadURL = [NSURL URLWithString:fullURL];
NSMutableURLRequest *dlRequest = [NSMutableURLRequest requestWithURL:downloadURL];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:dlRequest delegate:self];
[theConnection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[[NSRunLoop currentRunLoop] run];
[theConnection start];
if(theConnection) { //me checking for connection which is 'true'
NSLog(#"Connection for %# worked", fullURL);
} else {
NSLog(#"Connection for %# failed", fullURL);
}
}
I had this problems too when I wanted to start NSURLConnection in a concurrent NSOperation.
Performing connection on main thread helped me solve the problem.
- (void)start {
if (![NSThread isMainThread]) {
[self performSelectorOnMainThread:#selector(start)
withObject:nil
waitUntilDone:NO];
return;
}
}
Also scheduling sonnection in [NSRunLoop currentRunLoop] helped me to solve the problem:
self.connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self
startImmediately:NO];
[self.connection scheduleInRunLoop:[NSRunLoop currentRunLoop]
forMode:NSRunLoopCommonModes];
[self.connection start];
You can take a look how it's done in CSMessage class that is part of CSUtils framework. Feel free to use given code on your own: https://github.com/cloverstudio/CSUtils
Put delegate in your class.h like:
#interface InitViewController : UIViewController<NSURLConnectionDelegate,NSURLConnectionDataDelegate>
In the end I re-wrote the whole class and got the delegates firing.
NSString *currentURL = [NSString stringWithFormat:#"%#/api/sync", apiURL];
NSLog(#"URL = %#", currentURL);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:currentURL]];
[request addValue:#"application/json" forHTTPHeaderField:(#"Accept")];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
Here are the delegates that now fire:
- (void)connection:(FileURLConnection*)connection didReceiveResponse:(NSURLResponse *)response
{
NSString *fileName = [[response URL] lastPathComponent];
NSString *filePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0]stringByAppendingPathComponent:fileName];
[[NSFileManager defaultManager] createFileAtPath:filePath contents:nil attributes:nil];
connection.file = [NSFileHandle fileHandleForUpdatingAtPath:filePath];
}
- (void)connection:(FileURLConnection *)connection didReceiveData:(NSData *)data
{
[connection.file writeData:data];
}
- (NSCachedURLResponse *)connection:(FileURLConnection *)connection willCacheResponse:(NSCachedURLResponse*)cachedResponse
{
return nil;
}
- (void)connectionDidFinishLoading:(FileURLConnection *)connection
{
[connection.file closeFile];
}
- (void)connection:(FileURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(#"GetFiles - didFailWithError - error : %# for URL %#", error, connection.currentRequest.URL);
}
The class now downloads the file (from my own API) and saves it on the device.
Just change this line and rest keep as it is in your code. Keep the scheduleInRunLoop line also.
NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:request
delegate:self startImmediately:NO];

NSURLConnection return bad cacheData

In my AppDelegate method I create cache
NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:(10 * 1024 * 1024) diskCapacity:(100 * 1024 * 1024) diskPath:nil];
[NSURLCache setSharedURLCache:URLCache];
I have next NSURLConnection class
#implementation ImageDownloader {
NSURLConnection *serverConnection;
NSMutableData *imageData;
}
- (void)startDownloading
{
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:self.link] cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10];
imageData = [NSMutableData new];
serverConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[serverConnection scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSRunLoopCommonModes];
[serverConnection start];
}
- (void)cancelDownloading
{
[serverConnection cancel];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[imageData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
UIImage *image = [[UIImage alloc] initWithData:imageData];
[self sendDelegateImage:image];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
[self sendDelegateImage:nil];
}
- (void)sendDelegateImage:(UIImage *)image
{
[self.delegate imageDownloader:self didLoadAtIndexPath:self.indexPath image:image];
}
#end
I use it when my tableView cells appears. In first load all good, and in first use of cache all good, but when I load my tableView in third time, cache data returned very small, and I have not image. Why NSURLConnection return bad cached data?
You could try implementing connection:didReceiveResponse:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.dataReceived = [[NSMutableData alloc] init];
}
From the docs:
In rare cases, for example in the case of an HTTP load where the
content type of the load data is multipart/x-mixed-replace, the
delegate will receive more than one connection:didReceiveResponse:
message. In the event this occurs, delegates should discard all data
previously delivered by connection:didReceiveData:, and should be
prepared to handle the, potentially different, MIME type reported by
the newly reported URL response.
Edit:
Also, just noticed you are using [NSMutableData new] to initialise your data; you should be using [NSMutableData alloc] init].

Objective C: Downloading File With Progress Bar [duplicate]

This question already has an answer here:
how to display progressbar during downloading video file from the server in to the iphone?
(1 answer)
Closed 9 years ago.
I am trying to put a progress bar that syncs during the download that is happening.
My app now can download a file using with this codes...
pdfData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:#"http://webaddress.com/pro/download/file.pdf"]];
NSString *resourcePDFPath = [[NSString alloc] initWithString:[[[[NSBundle mainBundle] resourcePath] stringByDeletingLastPathComponent] stringByAppendingPathComponent:#"Documents"]];
pdfFilePath = [resourcePDFPath stringByAppendingPathComponent:#"myPDF.pdf"];
[pdfData writeToFile:pdfFilePath atomically:YES];
During the process of this code the app stopped during download, is it normal?
Now what I want is to put a progress bar during that stop time while downloading.
I tried looking into the codes I found online but I'm a bit confused, I think I need a step-by-step-well-explained reference.
Using AFNetworking,
here progress is the UIProgressview
#import <AFNetworking/AFNetworking.h>//add to the header of class
-(void)downloadShowingProgress
{
progress.progress = 0.0;
currentURL=#"http://www.selab.isti.cnr.it/ws-mate/example.pdf";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:currentURL]];
AFURLConnectionOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *filePath = [[paths objectAtIndex:0] stringByAppendingPathComponent:#"MY_FILENAME_WITH_EXTENTION.pdf"];
operation.outputStream = [NSOutputStream outputStreamToFileAtPath:filePath append:NO];
[operation setDownloadProgressBlock:^(NSUInteger bytesRead, NSUInteger totalBytesRead, NSUInteger totalBytesExpectedToRead) {
progress.progress = (float)totalBytesRead / totalBytesExpectedToRead;
}];
[operation setCompletionBlock:^{
NSLog(#"downloadComplete!");
}];
[operation start];
}
Using NSURLConnection
-(void)downloadWithNsurlconnection
{
NSURL *url = [NSURL URLWithString:currentURL];
NSURLRequest *theRequest = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:60];
receivedData = [[NSMutableData alloc] initWithLength:0];
NSURLConnection * connection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
}
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
progress.hidden = NO;
[receivedData setLength:0];
expectedBytes = [response expectedContentLength];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[receivedData appendData:data];
float progressive = (float)[receivedData length] / (float)expectedBytes;
[progress setProgress:progressive];
}
- (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
- (NSCachedURLResponse *) connection:(NSURLConnection *)connection willCacheResponse: (NSCachedURLResponse *)cachedResponse {
return nil;
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pdfPath = [documentsDirectory stringByAppendingPathComponent:[currentURL stringByAppendingString:#".mp3"]];
NSLog(#"Succeeded! Received %d bytes of data",[receivedData length]);
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
[receivedData writeToFile:pdfPath atomically:YES];
progress.hidden = YES;
}
Use ASIHTTPRequest.h class and ASINetworkQueue.h for downloading the file.
and use this code for progress bar
request = [ASIHTTPRequest requestWithURL:#"http://webaddress.com/pro/download/file.pdf];
[request setDelegate:self];
[request setDownloadProgressDelegate:progressView];
[request setShowAccurateProgress:YES];
request.shouldContinueWhenAppEntersBackground=YES;
request.allowResumeForFileDownloads=YES;
[request startAsynchronous];
this may help you
I'm afraid it's not normal, use asynchronous method to get the NSData.
First of all you should be clear whether to make a synchronous call or asynchronous.
For mobile apps or any other app asynchronous is preferred one.
Once you are clear use NSURLConnection class to fetch the data from the URL.
Here is the good tutorial.
And for loading you can start progress while starting the request and stop it when you receive connection:didFailWithError: or connectionDidFinishLoading: delegate method.

iOS Integrate Sendy API Into App

I am making an iPhone app that will need to communicate with the Sendy API. I believe that it uses some kind of JSON, but I'm not really sure, nor do I know where to start. I'm particularly interested in the subscribe portion of the API. Basically, I need to know how to talk to the Sendy API from my app.
Any help is appreciated.
My code:
- (IBAction)submitButtonPressed:(id)sender
{
self.data = [[NSMutableData alloc] initWithLength:0];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:#"http://www.erwaysoftware.com/sendy/subscribe"]];
[request setHTTPMethod:#"POST"];
[request setValue:#"john#test.com" forHTTPHeaderField:#"email"];
[request setValue:#"john" forHTTPHeaderField:#"name"];
[request setValue:#"LxxxxxxxxxxxxxxxxxxxxQ" forHTTPHeaderField:#"list"];
[request setValue:#"true" forHTTPHeaderField:#"boolean"];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self];
[conn start];
}
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.data setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d {
[self.data appendData:d];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error", #"")
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", #"")
otherButtonTitles:nil] show];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseText = [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding];
// Do anything you want with it
NSLog(#"%#", responseText);
}
When the log happens, the string is empty. I know through breakpoints that the last method is called.
Looking at the API it's all just plain text response.
Since it's a POST you can use an NSURLConnection to compose the request. See this question for information on formatting the response.
An alternative is to use something like AFNetworking or RestKit that might be a little more friendly if you're doing more work with APIs.
I'm guessing you've already resolved this but in case anyone else gets stuck here (as I did) I thought I'd post what I did to get it to work.
The first thing you need to do is create a category called NSString+URLEncoding (or whatever) which is going to take your email and name fields from blah#blah.com and turn it into blah%40blah.com. I modified this from the handy blog post found here
#interface NSString (URLEncoding)
-(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding;
#end
#import "NSString+URLEncoding.h"
#implementation NSString (URLEncoding)
-(NSString *)urlEncodeUsingEncoding:(NSStringEncoding)encoding {
return (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL,
(CFStringRef)self,
NULL,
(CFStringRef)#"!*'\"();:#&=+$,/?%#[]% ",
CFStringConvertNSStringEncodingToEncoding(encoding)));}
#end
Ok so now just import NSString+URLEncoding.h and add the following code and you'll be in business. This post helped me with this part
- (IBAction)submitButtonPressed:(id)sender
{
NSMutableURLRequest *newRequest = [[NSMutableURLRequest alloc]initWithURL:[NSURL URLWithString:#"http://stashdapp.com/sendy/subscribe"]];
[newRequest setHTTPMethod:#"POST"];
[newRequest setValue:#"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
NSString *email = #"name#domain.com";
NSString *name = #"First Lastname";
NSString *list = #"XXXXXXXXXXXXXXXXXX";
NSString *postData = [NSString stringWithFormat:#"email=%#&boolean=true&name=%#&list=%#", [email urlEncodeUsingEncoding:NSUTF8StringEncoding],[name urlEncodeUsingEncoding:NSUTF8StringEncoding],list];
[newRequest setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn = [NSURLConnection connectionWithRequest:newRequest delegate:self];
[conn start];
}
You still include the delegate methods which you quoted in your question.
Hope it helps someone!

Resources