需要卷曲方面的帮助

需要卷曲方面的帮助

当我运行 Windows 桌面时,以下命令运行良好,但如果我从 Linux 服务器运行,则无法找到资源。

在 Windows 上,这就是我给出的工作方式。

curl -H "Content-Type:application/json" -H "Accept:application/json" -u username:password -X GET http://10.188.102.94:23450/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'00000060489'

我尝试了这种方式作为 http 之前的 Quote 但在 UNIX shell 上仍然失败:

curl -H "Content-Type:application/json" -H "Accept:application/json" -u username:password 'http://10.188.102.94:23450/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20%27900000060489'

这里它返回这个错误:

{
    "errorSource" : "/ConfigurationManager/v1/views/lun-paths?=hostGroup.storageDeviceId%20eq%20900000060489",
    "message" : "Resource information could not be obtained.",
    "cause" : "The specified storage system is invalid.",
    "solution" : "Check and, if necessary, revise the query parameter to obtain information about the storage system."
}

答案1

您的最新编辑最终显示它已在 Windows 系统上成功运行:

curl -H "Content-Type:application/json" -H "Accept:application/json" -u username:password -X GET http://10.188.102.94:23450/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'00000060489'

您必须记住,Windows CMD 和 UNIX/Linux shell 的引用规则完全不同。引用 URL,您更有可能成功,特别是因为参数之一似乎是文字$query,否则对于 UNIX/Linux shell,该文字将被解释为要扩展的变量。

为了确认 Windows 的引用规则,我在 Windows CMD 窗口中运行了您的命令,将目标 IP 地址从 10.188.102.94 更改为我的 Linux 服务器(“linuxServer”)的 IP 地址,并nc -l 23450在那里运行以创建传入的侦听端口要求。

# Linux Server
nc -vvv -l 23450
Listening on linuxServer 23450

# Windows PC
curl -H "Content-Type:application/json" -H "Accept:application/json" -u username:password -X GET http://linuxServer:23450/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'00000060489'

Linux 服务器上收到的输出(HTTP 请求):

Connection received on linuxServer 13252
GET /ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'00000060489' HTTP/1.1
Host: linuxServer:23450
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
User-Agent: curl/7.83.1
Content-Type:application/json

您可以清楚地看到 URL 路径包含嵌入的单引号。事实证明RFC 3986说这些字符是允许的,所以尽管它们不常见,但它们是可以接受的。这意味着我们需要用双引号将它们引起来,以确保它们不被 shell 处理 - 但同样,文本$query不能包含在双引号中,因为否则它会被作为 shell 变量进行处理。在这里,我选择单引号 URL 的第一部分,然后中途切换为使用双引号('abc'"def"作为单个字符串处理abcdef):

curl -H "Content-Type:application/json" -H "Accept:application/json" -u username:password 'http://linuxServer:23450/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'"'00000060489'"

Linux 服务器上收到的输出(HTTP 请求):

Connection received on linuxServer 13993
GET /ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'00000060489' HTTP/1.1
Host: linuxServer:23450
Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
User-Agent: curl/7.83.1
Content-Type:application/json

是一样的,所以我们就达到了要求。将IP地址替换为你的真实IP地址,我们最终得到了这个解决方案:

curl -H "Content-Type:application/json" -H "Accept:application/json" -u username:password 'http://10.188.102.94:23450/ConfigurationManager/v1/views/lun-paths?$query=ldev.storageDeviceId%20eq%20'"'00000060489'"

相关内容