简体   繁体   English

iOS / Swift2-列出远程目录中的所有文件

[英]IOS / Swift2 - List all files in remote directory

I have a server running nginx. 我有一台运行nginx的服务器。 I have a directory in my server where I have several audio files. 我的服务器上有一个目录,其中有几个音频文件。 I replaced my real url by "url". 我用“ url”替换了真实的url。

How can I list all files in that directory in a table. 如何在表中列出该目录中的所有文件。

When I print weContent I get: 当我打印weContent时,我得到:

403 Forbidden 403禁止

override func viewDidLoad() {
    super.viewDidLoad()
    let url = NSURL(string: "url")!
    //self.webView.loadRequest(NSURLRequest(URL: url))

    let task = NSURLSession.sharedSession().dataTaskWithURL(url) { (data, response, error) -> Void in

        // Will happen when task completes
        if let urlContent = data {
            let webContent = NSString(data: urlContent, encoding: NSUTF8StringEncoding)
            print(webContent)
            dispatch_async(dispatch_get_main_queue(), { () -> Void in
                self.webView.loadHTMLString(String(webContent!), baseURL: nil)
            })
        } else {
            // Show error message
        }
    }
    task.resume()
}

Thank you 谢谢

A 403 error usually means that the user or group doesn't have permission to access to the resource you are requesting. 403错误通常表示用户或组无权访问您所请求的资源。

You should try changing the permissions on the directory you are trying to access to: o+r or change the owner of the directory to the appropriate user. 您应该尝试更改要访问的目录的权限:o + r或将目录的所有者更改为适当的用户。 (I generally use apache servers, the user is www) (我一般使用apache服务器,用户是www)

Nginx provides it's own documentation on 403 errors here Nginx在此处提供有关403错误的自有文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM