4

This is my code.

- (void)loadData:(NSString *)url {
    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
    [[NSURLConnection alloc] initWithRequest:request delegate:self];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
    NSLog(@"connection found---------");
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
    NSLog(@"reciving data---------");
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    NSLog(@"connection fail---------");
    [self.pddelegate connectionError];
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"data posting done---------");
    [self.pddelegate dataPosted];
}

It is not working if url become bigger and give connection fail in logs.

Like

url=@".......order_details&admin=29&tableid=89&waiter_id=18&items=MzQ6MSwxMToxLDMzOjEsNjc6MSwzOToxLDY5OjEsNTY6MSw2ODoxLDg6MSw1NToxLDYyOjEsNzY6MSw0MToxLDIwOjEsNjE6MQ=="
Regexident
  • 29,441
  • 10
  • 93
  • 100
Suraj Gupta
  • 200
  • 9
  • 1
    What doesn't work and have you encoded any characters before trying to create the URL. – Wain May 23 '13 at 05:52
  • yes i am using base64 encoding before creating url – Suraj Gupta May 23 '13 at 05:53
  • 1
    Could you please put this:`NSLog(@"%@", [error localizedDescription]);` in `connection:didFailWithError:` and tell us what the output is? – Simon M May 23 '13 at 05:54
  • May be issue is not with size of url but with escape characters .. – utsabiem May 23 '13 at 06:04
  • @SimonM output of above log is bad URL – Suraj Gupta May 23 '13 at 06:34
  • It'd be helpful if you'd show a complete URL that's failing or at least indicate the length of the string when the problem seems to start. I can't tell from looking at the tail end of your URL how long the whole thing is. – Caleb May 23 '13 at 13:24

3 Answers3

0

see this SO post for get type request length What is the maximum length of a URL in different browsers?

for sending big string use POST type request instead of GET type.

Community
  • 1
  • 1
Manish Agrawal
  • 10,958
  • 6
  • 44
  • 76
0

We have there are two methods for sending data. 1. GET Method : Which is used for fixed length or limited length of string only. 2. POST Method : Which is used to send more string while comparing get method.

I have given the example 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 any error occur errStr will show the error.

Karthik
  • 747
  • 4
  • 21
  • 48
0

In the past, I have used some URL's that are around 2000 characters in length in iOS with no problem. NSURL, NSURLRequest, and NSURLConnection all managed just fine. If your URL is shorter than that, the problem is probably not due to its length, but instead related to the way the URL is constructed.

Caleb
  • 124,013
  • 19
  • 183
  • 272