【发布时间】: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 并正确获取数据?
任何帮助将不胜感激。谢谢。
【问题讨论】:
-
Stack Overflow 是一个编程和开发问题的网站。这个问题似乎离题了,因为它与编程或开发无关。请参阅帮助中心的What topics can I ask about here。也许Super User 或Unix & Linux Stack Exchange 会是一个更好的提问地点。
标签: linux url curl sharepoint urlencode