【问题标题】:Objective-C - HTTP load failed (error code: -1004 [1:61]) for Task in iOS11Objective-C - iOS11 中任务的 HTTP 加载失败(错误代码:-1004 [1:61])
【发布时间】:2017-09-22 19:03:25
【问题描述】:

我正在尝试使用 URLSession 执行数据任务,当我在 iOS11 设备 (iPhone 5S) 上运行它时出现控制台错误:

2017-09-22 15:22:17.942015-0300 app[1355:283536] TIC TCP Conn Failed [3:0x1c417af40]: 1:61 Err(61) 
2017-09-22 15:22:17.943698-0300 app[1355:283536] Task <A32F0275-75C3-4F64-AB92-2E37527AB813>.<0> HTTP load failed (error code: -1004 [1:61])
2017-09-22 15:22:17.945265-0300 app[1355:283676] NSURLConnection finished with error - code -1004

在模拟器上运行它不会发生。

是什么原因造成的或如何解决?

这就是我正在做的事情

#define kEcardURL @"https://example.com/mobile/services/ecard/"

- (void)doSomething {

    //Params Configuration
    NSDictionary *parameters = [NSDictionary dictionaryWithObjectsAndKeys:
                          [oauth.userData valueForKey:@"wsuserid"], @"token",
                          nil];

    NSString *path = @"fotoCartao";
    NSData* params = [NSJSONSerialization dataWithJSONObject:parameters options:0 error:nil];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", kEcardURL, path]];
    NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
    [urlRequest setHTTPMethod:@"POST"];
    [urlRequest setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
    [urlRequest setHTTPBody:params];


    NSURLSessionDataTask *dataTask = [[self session] dataTaskWithRequest:urlRequest completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

    NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;

    if ([data length] > 0 && error == nil) {
      if ([httpResponse statusCode] == 200) {
        //do stuff
      }
    }
  }];
  [dataTask resume];
  }
}

- (NSURLSession *)session {
  static dispatch_once_t onceToken;
  dispatch_once(&onceToken, ^{
  // Session Configuration
  NSURLSessionConfiguration *defaultConfigObject = [NSURLSessionConfiguration defaultSessionConfiguration];

  // Initialize Session
  _session = [NSURLSession sessionWithConfiguration: defaultConfigObject delegate: nil delegateQueue: [NSOperationQueue mainQueue]];
  });
  return _session;
}

【问题讨论】:

  • 你需要显示一些代码。
  • 编辑您的问题以将其添加到那里,否则它不是很可读。还要添加所有相关代码。据我所知,问题可能出在您的网址上,但我们看不到。

标签: http ios11


【解决方案1】:

通过运行以下命令确保该 url 受支持:

curl -v https://example.com/mobile/services/ecard/

nscurl --verbose --ats-diagnostics https://example.com/mobile/services/ecard/

确认您没有使用 Apple 不再支持的密码哈希和协议。

IOS 11 不再支持这些:

密码:

  • RC4
  • 3DES-CBC
  • AES-CBC

哈希:

  • MD5
  • SHA-1

密钥大小:

协议:

  • http://
  • SSLv3
  • TLS 1.0
  • TLS 1.1

如果它们不受支持,您可以通过使用将域列入白名单 应用程序 plist 文件中的 NSAppTransportSecurity 属性。

【讨论】:

    【解决方案2】:

    [已解决] 这是由服务器端的 TLS 版本 (1.1) 引起的。 正如韦恩所说,在 NSAppTransportSecurity 添加一个条目解决了这个问题。

    Plist 条目:

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>example.com</key>
            <dict>
                <key>NSExceptionAllowsInsecureHTTPLoads</key>
                <true/>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.1</string>
                <key>NSExceptionRequiresForwardSecrecy</key>
                <false/>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
        </dict>
    </dict>
    

    【讨论】:

    • 好吧......这并没有真正解决其他人的问题。什么是 TLS,我在服务器端哪里可以找到它??????
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-11-07
    • 2018-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-06
    • 2018-03-09
    相关资源
    最近更新 更多