[英]URL encoding with SharePoint URL and cURL
I am new to using CURL
.我是使用
CURL
新手。 I am trying to connect to a SharePoint
URL and pull the data in the form of json
.我正在尝试连接到
SharePoint
URL 并以json
的形式提取数据。 My URL looks like this:我的网址如下所示:
.../_api/web/lists/GetByTitle('titles list')/items
If I give the URL as it is without any encoding, it fails with a HTTP/1.1 400 Bad Request
error.如果我提供没有任何编码的 URL,它会失败并显示
HTTP/1.1 400 Bad Request
错误。
I tried using -G
and --data-urlencode
like below:我尝试使用
-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"
doing this will convert my URL to .../_api/web/lists/GetByTitle?%28%27titles%20list%27%29&/items
这样做会将我的 URL 转换为
.../_api/web/lists/GetByTitle?%28%27titles%20list%27%29&/items
But it fails with HTTP/1.1 404 Not Found
since using -G
will append to the URL with a ?
但它因
HTTP/1.1 404 Not Found
而失败,因为使用-G
将附加到带有?
and &
.和
&
。 Putting ?
放
?
and &
to append to the URL will give me a different URL and hence the 404 not found
error.和
&
附加到 URL 会给我一个不同的 URL,因此404 not found
错误。
I have no issues accessing other end points like ../_api/web/lists
since there is no need to encode it I guess.我在访问其他端点(如
../_api/web/lists
没有问题,因为我猜不需要对其进行编码。
How do I properly encode my URL and get the data without any errors?如何正确编码我的 URL 并在没有任何错误的情况下获取数据?
Any help would be appreciated.任何帮助,将不胜感激。 Thank you.
谢谢你。
I was able to solve the issue by directly giving URL with the encoded characters to cURL
command.我能够通过将带有编码字符的 URL 直接提供给
cURL
命令来解决这个问题。 Like this:像这样:
curl -v -L --ntlm --user user:password -H 'Accept: application/json;odata=verbose' ".../_api/web/lists/GetByTitle%28%27titles%20List%27%29/items"
I hope this helps someone.我希望这可以帮助别人。 I know I am no expert with linux or
cURL
and any better answers to this are welcome.我知道我不是 linux 或
cURL
专家,欢迎对此提供更好的答案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.