I've a strange problem, I'm working on a project that I've to request from a server, When requesting a URL
without parameters using GET
method, it works fine and return the desired data, but when using the same code to call the URL
and sending a parameters to it, it fail with this error:
error: Error Domain=NSURLErrorDomain Code=-1001 UserInfo=0xed4870 "timed out"
My code is the following:
NSString *param = @"pageNumber=2";
NSURL *url = [NSURL URLWithString:@"http://myWebsite/api/Soccor/"];//When using this, it works fine
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://myWebsite/api/Soccor?%@", param]];//When using this, it gives me the request time out error.
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest addValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"GET"];
[theRequest setTimeoutInterval:10];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
Any clue why it returns error when sending parameters with the URL
?