0

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?

The Man
  • 1,462
  • 3
  • 23
  • 45

1 Answers1

2

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

melopsitaco
  • 176
  • 4
  • Now how would I reference the data in my php code? $_POST['whatGoesHere']; – The Man Jul 31 '12 at 12:53
  • In this example the datagoes inside the POST stream. I never have used PHP but may be this link can be useful for you http://stackoverflow.com/questions/3362145/i-cant-read-my-post-http-requests-body-with-php If you still want to use key values you can set the NSString* body like: NString body = [NSString stringWithFormat:@"vID=%@&pop=%d&tId=%@",videoId,pushPull,[objectSaver openWithKey:@"userId"]]; You will find more info about HTTP POST in the wikipedia: http://en.wikipedia.org/wiki/POST_(HTTP) – melopsitaco Jul 31 '12 at 13:10