【问题标题】:iOS downloading tar file from https urliOS从https url下载tar文件
【发布时间】:2012-10-03 19:45:46
【问题描述】:

我正在尝试从 https 网址下载文件。使用 http 可以正常工作,但对于 https 就不行了。我将在下面发布我当前的代码,但出于个人目的,我不想发布用于 URL 的 IP 地址,因此我将在其位置放置“ipAddress”。我应该提到 https 来自自签名证书。

-(void)downloadPDF: (NSInteger)numDay {

NSString *homeDir = NSHomeDirectory();

NSString *filePath = [NSString stringWithFormat: @"%@/%@%@%@", homeDir, @"Documents/", @"File", @".tar"];
NSString *dirPath = [NSString stringWithFormat: @"%@/%@", homeDir, @"Documents/"];
    NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", @"ipAddress", @'File", @".tar"]];

NSData *urlData = [NSData dataWithContentsOfURL:url];
[urlData writeToFile:filePath atomically:YES];
[mywebview loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]]];

}

我已经尝试了很多其他的东西,从使用 NSURLConnection 到下载整个库,但我一定错过了一些东西。我也有:

- (void)connection:(NSURLConnection *)connection willSendRequestForAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge{

}

在我的应用程序委托 .m 文件中,如其他文件中所述。任何帮助将不胜感激,如果您需要更多信息,请在 cmets 中告诉我。

【问题讨论】:

    标签: ios5 https download nsurlconnection


    【解决方案1】:

    https 需要完全限定的域地址 (FQDA)。它不适用于 IP。

    【讨论】:

    • 这只是iOS的东西吗?我可以从浏览器下载有问题的项目,甚至在我的 iPad 上。
    • 这是 https 的东西。 ssl 证书中嵌入了 FQDN,因此如果您指向的 url 不匹配,它应该会失败。
    猜你喜欢
    • 2016-11-30
    • 1970-01-01
    • 1970-01-01
    • 2012-08-24
    • 2012-08-06
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 1970-01-01
    相关资源
    最近更新 更多