【发布时间】:2017-01-11 18:25:28
【问题描述】:
所以,这个问题很难简单描述,我觉得我应该先在这里问一下,然后再在 AFNetworking github 上提出问题。故事是这样的:
// Definition for words in the story.
Characters:
- APP: Our iOS app, which POST requests to a URL's API (has user input from a UITextField)
APP's networking connection using framework AFNetworking 3.0
- DEV: Us developers, who created the iOS app.
- CUST: The troublesome customer, who live far from DEV.
CUST used app before, then one day it doesn't work anymore (S1 has died).
Server:
- S1: The CUST's primary server (died for some reasons). This has the IP address = ip1
- S2: The CUST's secondary server (works fine). This has the IP address = ip2
- URL: The domain URL point to both server (using load balancing or something like that, I dunno).
// End-of-definition
故事开始:
CUST使用app,输入URL,连接失败。 CUST在iPad浏览器中输入URL,正常访问。 CUST 询问 DEV 检查发生了什么。 DEV在app中输入URL,连接正常。当时DEV不知道CUST有2台服务器。
CUST 和DEV 都感到绝望,挣扎了好一阵子。 CUST 尽其所能(使用https / http,添加/删除www,删除应用程序并重新安装)。 DEV 被不合理的原因分散了注意力(连接器错误,api 错误......)。然后CUST 记住他有两台服务器。 CUST 分享了 IP addresses 供 DEV 检查。这时候DEV 发现S1 已经死了,而S2 还没有死。
所以,DEV 得到了CUST 无法使用APP 访问URL 的原因:S1 已经死了。 但是,对于 SO,真正的问题是:
为什么它在我们这边有效,而在CUST 那边却不行?为什么APP(在DEV 的手中)转到S2 但在CUST 的手中,它转到S1(并死了)?但是为什么CUST可以正常使用iPad的浏览器访问URL呢?
这和 DNS 有关系吗?虚拟专用网?负载均衡?我很想为这个问题找个理由。
感谢阅读。随意编辑这个问题,因为我也努力尽可能简单地描述这个问题。
更新 1:
作为James Jayson 询问APP 如何连接到URL,它使用AFNetworking 3.0 和AFHTTPSessionManager 并进行一些设置:
self.sessionManager = [[AFHTTPSessionManager alloc] initWithBaseURL:baseUrl sessionConfiguration:[NSURLSessionConfiguration defaultSessionConfiguration]];
self.sessionManager.securityPolicy.allowInvalidCertificates = YES;
self.sessionManager.securityPolicy.validatesDomainName = NO;
self.sessionManager.requestSerializer.timeoutInterval = timeout;
self.sessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
// Call API:
[self.sessionManager POST:path parameters:dictParams progress:nil success:^(NSURLSessionTask *task, id responseObject) {
// success block
} failure:^(NSURLSessionTask *task, NSError *error) {
// failure block
}
更新 2:
所以,现在我有了一些新的东西:CUST 使用 iOS 9.3.5,DEV 使用 iOS 10.x。 DEV尝试在iOS 9.3.5设备上调试,出现CUST的错误,错误信息类似于this(几乎相同,仅URL不同)。
日志: 错误域=NSURLErrorDomain 代码=-1004 “无法连接到服务器。” UserInfo={NSErrorFailingURLStringKey=APIURL, _kCFStreamErrorCodeKey=-2200, NSErrorFailingURLKey=APIURL, NSLocalizedDescription=无法连接到服务器。, _kCFStreamErrorDomainKey=4, NSUnderlyingError=0x16146990 {错误域=kCFErrorDomainCFNetwork 代码=-1004 "(null)" UserInfo={_kCFStreamErrorDomainKey=4, NSErrorPeerAddressKey={length = 16, capacity = 16, bytes = 0x100201bb253ce7160000000000000000},_kCFStreamErrorCodeKey=-2200}}}
现在DEV 正在努力解决如何处理此错误。请帮忙。
【问题讨论】:
标签: ios objective-c hosting afnetworking-3 ios9.3