为什么 dataTaskWithURL
在 iOS 上有效,但在 macOS 上无效?
错误信息是:
Client-Error: A server with the specified hostname could not be found.
我的日常安排如下:
- (void)loadHTML {
NSString *urlString = @"https://morph.zone/modules/newbb_plus/viewtopic.php?topic_id=12630&forum=10";
NSURL *url = [NSURL URLWithString:urlString];
NSURLSessionDataTask *downloadTask = [[NSURLSession sharedSession] dataTaskWithURL:url completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (error != nil) {
NSLog(@"Client-Error:%@",error.localizedDescription);
}
else {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
if (httpResponse.statusCode < 200 || httpResponse.statusCode > 299) {
NSLog(@"Server-Error:%ld",httpResponse.statusCode);
}
else {
NSLog(@"Data downloaded");
}
}
}];
[downloadTask resume];
}
最佳答案
关于macos - NSURLSessionDataTask 在 macOS 上不起作用, "A server with the specified hostname could not be found.",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58042612/