【问题标题】:Load image/file stored in FTP server on WebView在 WebView 上加载存储在 FTP 服务器中的图像/文件
【发布时间】:2016-03-09 16:13:36
【问题描述】:

我正在尝试在 web 视图上加载存储在 FTP 服务器中的图像。问题是使用

let url = "ftp://example.com/images/image1.jpg"
let requestURL = NSURL(string:url)
let request = NSURLRequest(URL: requestURL!)
webView.loadRequest(request)

仅显示白屏,因为 FTP 服务器要求输入用户名和密码以授予访问权限。所以我的问题是:如何验证自己的身份,以便将来自 ftp url 的图像加载到 webview 中?

【问题讨论】:

    标签: ios swift webview ftp


    【解决方案1】:

    您可以使用此mask 构建 URL。

    ftp://username:password@hostname/
    

    let login       = "LoginName"
    let password    = "Password"
    let ftpServer   = "ftp.server.com"
    let fileName    = "example.txt"
    
    let ftpUrl = NSURL(string: "ftp://\(login):\(password)@\(ftpServer):21/\(fileName)")
    

    【讨论】:

    • ftp://user:pass@ftp.server.com/carpet/image1.jpg一样尝试,但没有成功。
    • 也许你必须设置 NSAllowsArbitraryLoads NSAppTransportSecurityNSAllowsArbitraryLoads
    猜你喜欢
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-11-06
    • 1970-01-01
    • 2011-07-05
    • 1970-01-01
    相关资源
    最近更新 更多