We have two methods for sending data. 1. GET method: used only for fixed length or limited string length. 2. POST method: used to send more lines when comparing the get method.
I gave an example of using PostMethod.
NSString *post =[[NSString alloc] initWithFormat:@"%@",YourString]; NSURL *url=[NSURL URLWithString:*@"YourURL like www.google.com"*]; NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]; NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]]; NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease]; [request setURL:url]; [request setHTTPMethod:@"POST"]; [request setValue:postLength forHTTPHeaderField:@"Content-Length"]; [request setValue: @"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"]; [request setHTTPBody:postData]; request.timeoutInterval = 60; NSError *error = nil; NSURLResponse *response; NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; NSString *errStr = _stringEmpty; @try { errStr = [error localizedDescription]; }@catch (NSException * exception){ }
If an error occurs, errStr will display an error.
source share