我有一个奇怪的问题,我正在处理一个我必须从服务器请求的项目,当URL
使用方法请求没有参数的情况下GET
,它工作正常并返回所需的数据,但是当使用相同的代码调用URL
并向其发送参数,它会因以下错误而失败:
error: Error Domain=NSURLErrorDomain Code=-1001 UserInfo=0xed4870 "timed out"
我的代码如下:
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];
任何线索为什么它在发送参数时返回错误URL
?