简体   繁体   English

使用 SharePoint URL 和 cURL 进行 URL 编码

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM