我得到这个错误只是在获取请求。在服务器端,我们有Apache HTTP服务器来管理对Tomcat的请求和响应。
有两个客户端Android和iOS。Android应用程序中的一切都很好。另一方面,在iOS应用程序中,所有POST响应都可以,问题只是GET响应。
我跟踪了请求,所有请求都在服务器端应用程序上接收,关于日志,服务器向客户端发送响应,但客户端没有得到任何响应。
这些解决方案都不适合我的情况。
我的一段代码:
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
manager.responseSerializer = [[AFHTTPResponseSerializer alloc] init];
NSData *data = [request.Data dataUsingEncoding:NSUTF8StringEncoding];
NSString *length = [NSString stringWithFormat:@"%lu", [data length]];
NSMutableURLRequest *urlRequest = [PagingManager makeURLRequest:length andUrl:_url];
[urlRequest setHTTPMethod:@"GET"];
NSArray *arr = [request.Data componentsSeparatedByString:@" "];
NSString *session = [PagingManager normalizeGetRequest:arr[0]];
NSString *query = [PagingManager normalizeGetRequest:arr[1]];
NSString *getReq = [NSString stringWithFormat:@"?s=%@&q=%@", session, query];
NSURL *getURL = [NSURL URLWithString:[_url concat:getReq]];
urlRequest.URL = getURL;
NSURLSessionDataTask *dataTask = [manager dataTaskWithRequest:urlRequest uploadProgress:nil downloadProgress:nil completionHandler:^
(NSURLResponse *response, id responseObject, NSError *error) {
if (error) {
DDLogError(@"ERROR: %@, reason: %@", @"connection failed with error", [error debugDescription]);
NSString *const TIMEOUT = @"TimeOut";
NSException *p = [[NSException alloc] initWithName:EXExceptionOnExchangeClientConnectionFail
reason:(error.code == NSURLErrorTimedOut) ? TIMEOUT : [error localizedDescription]
userInfo:nil];
EXExchangeExceptionEventArgs *eventArgs = [[EXExchangeExceptionEventArgs alloc] initWithRequest:_request andError:p];
[self exchangeException:eventArgs];
_isRunning = NO;
} else {
NSString *responseString = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding];
NSData *decryptData = [[IOCryptographer Current] asDataDecryptString:responseString];
if (_request.ReqMethod == GET) {
DDLogDebug(@"Cache-Control Max-Age : %@", ((NSHTTPURLResponse *) response).allHeaderFields[@"Cache-Control"]);
DDLogDebug(@"All header of response in GET : %@", ((NSHTTPURLResponse *) response).allHeaderFields);
DDLogDebug(@"response: %@ and responseObject: %@", response, responseObject);
NSCachedURLResponse *cachedURLResponse = [[NSCachedURLResponse alloc] initWithResponse:response data:decryptData];
[NSURLCache.sharedURLCache storeCachedResponse:cachedURLResponse forRequest:cacheRequest];
} else {
DDLogDebug(@"All header of response in POST : %@", ((NSHTTPURLResponse *) response).allHeaderFields);
}
[_dataStream appendData:decryptData];
[self connectionDidFinishLoadingWithData:responseString];
}
}];
[dataTask resume];
还有我App的日志:
2018-06-04 12:41:22.871344 0430 App Name[53990:2111182]TIC读取状态[4:0x60800016ec40]: 1:57 2018-06-04 12:42:27.006807 0430 AppName[53990:2112128]TIC读取状态[5:0x60c000170500]: 1:57 2018-06-04 12:42:47.084334 0430 AppName[53990:2112128]TIC读取状态[6:0x60c00016f000]: 1:57 2018-06-04 12:42:47.085662 0430 AppName[53990:2112128]任务
我想这个问题源于Apache。
这个问题有什么解决方案吗?感谢您的帮助。
最后,3周后我找到了一个解决方案。我们将“Content-long”设置为标头,Apache(WWW)删除了那些包含它的请求。所以我删除了那个标头,现在一切正常:)
我面临着同样的问题,我附上了一张决议的截图,以显示我是如何解决这个问题的。
在我的情况下,问题是API请求被服务器Sucuri/CloudAgent阻止(或者你可以说防火墙服务)。禁用防火墙解决了这个问题