首页 > 解决方案 > 在 webdav 客户端中请求自定义字段

问题描述

我尝试了许多不同的方法来读取带有自定义详细信息的 nextCloud api 目录,例如:

'<?xml version="1.0" encoding="UTF-8"?>
 <d:propfind xmlns:d="DAV:">
   <d:prop xmlns:oc="http://owncloud.org/ns">
     <d:getlastmodified/>
     <d:getcontentlength/>
     <d:getcontenttype/>
     <oc:permissions/>
     <d:resourcetype/>
     <oc:share-types />
     <oc:fileid />
     <d:getetag/>
   </d:prop>
 </d:propfind>'

首先,我尝试使用 child_process 运行 curl 命令,例如:

var command = `curl -u username:password 'https://cloud.example.com/remote.php/dav/files/username/folder' -X PROPFIND --data '<?xml version="1.0" encoding="UTF-8"?>
 <d:propfind xmlns:d="DAV:">
   <d:prop xmlns:oc="http://owncloud.org/ns">
     <d:getlastmodified/>
     <d:getcontentlength/>
     <d:getcontenttype/>
     <oc:permissions/>
     <d:resourcetype/>
     <d:getetag/>
   </d:prop>
 </d:propfind>'`

import { exec } from "child_process"

const child = exec(command, (error, stdout, stderr) => {
        if (error) {
            console.log(`error: ${error.message}`);
            return;
        }
        if (stderr) {
            console.log(`stderr: ${stderr}`);
            return;
        }
        console.log(`stdout: ${stdout}`);

        return stdout;
      });

当我运行它时,我收到了这个错误消息,它没有说明它有什么问题

error: Command failed: curl -u username:password 'https://cloud.example.com/remote.php/dav/files/username/folder' -X PROPFIND --data '<?xml version="1.0" encoding="UTF-8"?>
 <d:propfind xmlns:d="DAV:">
   <d:prop xmlns:oc="http://owncloud.org/ns">
     <d:getlastmodified/>
     <d:getcontentlength/>
     <d:getcontenttype/>
     <oc:permissions/>
     <d:resourcetype/>
     <d:getetag/>
   </d:prop>
 </d:propfind>'

但是,当我复制错误消息在另一个终端实例上返回的相同 curl 命令时,我在控制台上打印了正确的 xml 文件。我真的很困惑为什么会这样?另外,我想将标准输出保存到 xml 变量中以供以后使用?我怎样才能做到这一点?我被这个问题困扰了好几个小时,我似乎无法弄清楚。谢谢你的帮助!

标签: node.jscurlwebdavnextcloud

解决方案


推荐阅读