Sending post
@implementation NetWorkUtil +(id) postRequestWithUrl:(NSString *) url andPostString:(NSString *) postString{ return [NetWorkUtil postRequestWithUrl:url andPostData:[NSData dataWithBytes:[postString UTF8String] length:strlen([postString UTF8String])] // !!! Do Not Use postString.length ]; } +(id) postRequestWithUrl:(NSString *)url andPostData:(NSData *)postData{ [url retain]; [postData retain]; NSMutableURLRequest * postRequest = [NSMutableURLRequest requestWithURL:([NSURL URLWithString:url])]; [postRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-Type"]; [postRequest setHTTPMethod:@"POST"]; [postRequest setHTTPBody:postData]; [url release]; [postData release]; return postRequest; } @end
-(void) sendingPost{ NSMutableURLRequest * postRequest = [NetWorkUtil postRequestWithUrl:mUrl andPostString:mPostData ]; [postRequest retain]; NSOperationQueue * queue = [NSOperationQueue new]; [NSURLConnection sendAsynchronousRequest:postRequest queue:queue completionHandler:^(NSURLResponse * response, NSData * data, NSError * error) { //handle error if exist if (error != nil ) { [self onError:error]; } else if(data != nil){ [self handleData:data]; }else { [self onError:error]; } }]; [queue release]; [postRequest release]; }