如何使用Ruby发送WebDAV标头?

时间:2016-06-24 17:54:02

标签: ruby webdav owncloud

我正在尝试使用ruby 2.0与Owncloud服务器(Sabre / webDAV)交谈。我有一个Curl示例,用于获取需要在HTTP标头中传递信息的文件列表。如何从Ruby传递此标头信息? net_dav docs似乎表明这是一个可用的方法,但红宝石错误似乎暗示:

编辑:修正语法错误headers =headers()

undefined method headers= for #<Net::DAV:0x00000001276d10> (NoMethodError)

卷曲命令:

# curl -s -X PROPFIND -H "Depth: 100" -H "Content-Type: application/json" -u ${username}:${passwd} https://myserver.net/remote.php/webdav | egrep href

ruby​​代码:

    # get list of files
    url = "https://myserver.net"
    path = "/remote.php/webdav/"

    dav = Net::DAV.new(url, :curl => false)
    dav.verify_server = true
    dav.credentials(user, pass)
    dav.headers ("Depth: 100")  # << something wrong ?

    # get list of files
    path = "/remote.php/webdav/"
    options = ''
    props = dav.propfind(path, options)

2 个答案:

答案 0 :(得分:0)

您关联的文档表示使用dav.headers(),您正在使用dav.headers =。也许这就是问题?

答案 1 :(得分:0)

最后,我发现rubygems.org上的v0.5 Gem远远落后于net_dav github页面上的v0.5代码。 This comment显示了如何获取有效的更新Gem。