我以前从未遇到过这个问题,但有时当我从服务器请求数据时(大约 10% 的时间),我从未收到响应(甚至没有标题!)并且请求超时。我使用networkQueue,它的设置是这样的
//when initializing
networkQueue = [[ASINetworkQueue queue] retain];
networkQueue.maxConcurrentOperationCount = 5;
networkQueue.delegate = self;
networkQueue.requestDidReceiveResponseHeadersSelector = @selector(request:DidReceiveHeaders:);
networkQueue.requestDidFinishSelector = @selector(NetworkQueueRouter:);
networkQueue.requestDidFailSelector = @selector(requestDidFail:);
我用这个方法初始化请求
-(void)sendRequest:(NSURL *)url withParams:(NSDictionary *)params andUserInfo:(NSDictionary *)info{
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
request.delegate = self;
NSString *jsonString = [params yajl_JSONString];
[request setPostValue:jsonString forKey:@"json"];
request.timeOutSeconds = 30;
if (info != nil) request.userInfo = info;
[networkQueue addOperation:request];
[networkQueue go];
}
我只有在使用 iPhone 或 iPhone Simulator 时才会遇到这个问题。有时,当请求一直持续时,我会用相同的请求检查我的浏览器,当 iPhone 仍在请求时,我会立即从浏览器中获得响应。
有谁之前经历过这个吗?