The Man
The Man

Reputation: 1462

http GET Limit (iPhone)

I know that http GET can be limited by the browser but what if you are using an iPhone? What is the limit if I do something like this?

 NSString *urlString = [NSString stringWithFormat:@"http://www.hdsjskdjas.com/urlPop.php?vID=%@&pop=%d&tId=%@",videoId,pushPull,[objectSaver openWithKey:@"userId"]];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSURLConnection *connect = [[NSURLConnection alloc] initWithRequest:request delegate:self];

if(connect) {
  //success;
} else {
    //failure;
}

Using this method to send information to my server what would be the limit to the number of characters in the url?

I want to be able to send over 24,000 characters to my sever...

If this is unachievable what would another option be?

Upvotes: 0

Views: 238

Answers (1)

melopsitaco
melopsitaco

Reputation: 186

To send big chunks of data you should use POST instead of GET. Here is an example of how to use it:

NSArray *keys = [NSArray arrayWithObjects:@"Content-Type", @"Accept", @"Authorization", nil]; 
NSArray *objects = [NSArray arrayWithObjects:@"application/json", @"application/json", mytoken, nil];
NSDictionary *headerFieldsDict = [NSDictionary dictionaryWithObjects:objects forKeys:keys];
NSData *bodyData = [body dataUsingEncoding: NSUTF8StringEncoding];

NSMutableURLRequest *theRequest = [[[NSMutableURLRequest alloc] init] autorelease];
[theRequest setURL:[NSURL URLWithString:url]];
[theRequest setHTTPMethod:@"POST"];
[theRequest setTimeoutInterval:timeout];
[theRequest setAllHTTPHeaderFields:headerFieldsDict];
[theRequest setHTTPBody:bodyData]; 

NSLog(@"userSendURL URL: %@ \n",url);

self.conn = [[[NSURLConnection alloc] initWithRequest:theRequest delegate:self] autorelease];

In this case body is a simple NSString object, but it can be anything that you can insert in a NSData object

Upvotes: 2

Related Questions