【问题标题】:URL encoding with SharePoint URL and cURL使用 SharePoint URL 和 cURL 进行 URL 编码
【发布时间】:2026-01-14 13:20:02
【问题描述】:

我不熟悉使用CURL。我正在尝试连接到SharePoint URL 并以json 的形式提取数据。我的网址如下所示:

.../_api/web/lists/GetByTitle('titles list')/items

如果我给出的 URL 没有任何编码,它会失败并出现 HTTP/1.1 400 Bad Request 错误。

我尝试使用-G--data-urlencode,如下所示:

curl -v -G -L --ntlm --user user:password -H 'Accept: application/json;odata=verbose' ".../_api/web/lists/GetByTitle" --data-urlencode "('titles list')" -d "/items"

这样做会将我的网址转换为.../_api/web/lists/GetByTitle?%28%27titles%20list%27%29&/items

但使用 HTTP/1.1 404 Not Found 会失败,因为使用 -G 将使用 ?& 附加到 URL。将?& 附加到URL 会给我一个不同的URL,因此会出现404 not found 错误。

访问../_api/web/lists 等其他端点没有问题,因为我猜不需要对其进行编码。

如何正确编码我的 URL 并正确获取数据?

任何帮助将不胜感激。谢谢。

【问题讨论】:

标签: linux url curl sharepoint urlencode


【解决方案1】:

我能够通过直接将带有编码字符的 URL 提供给 cURL 命令来解决这个问题。像这样:

curl -v -L --ntlm --user user:password -H 'Accept: application/json;odata=verbose' ".../_api/web/lists/GetByTitle%28%27titles%20List%27%29/items"

我希望这对某人有所帮助。我知道我不是 linux 或 cURL 方面的专家,欢迎任何更好的答案。

【讨论】: