I am trying to download some data in the form of json
from a SharePoint
API. I was able to do it using WGET
:
wget --user user --password password --header='Accept: application/json;odata=verbose' "URL"
and I am trying to do the same thing with CURL.
I tried using different headers and authentication mechanisms, but it always gives me the bad request error. Below are the commands I tried:
curl -v --user user:password "URL" curl -v --user user:password -H 'Accept: application/json;odata=verbose' "URL" curl -v --ntlm --user user:password -H 'Accept: application/xml' "URL" curl -v --anyauth --user user:password -H 'Accept: application/xml' "URL"
Below is the output I get:
* About to connect() to sharepoint2.domain.com port 80 (#0) * Trying xx.xx.xx.xx... connected * Connected to sharepoint2.domain.com (xx.xx.xx.xx) port 80 (#0) > GET <path> HTTP/1.1 > User-Agent: curl/7.19.7 (x86_64-redhat-linux-gnu) libcurl/7.19.7 NSS/3.27.1 zlib/1.2.3 libidn/1.18 libssh2/1.4.2 > Host: sharepoint2.domain.com > Accept: application/json;odata=verbose > < HTTP/1.1 400 Bad Request < Content-Type: text/html; charset=us-ascii < Server: Microsoft-HTTPAPI/2.0 < Date: Mon, 12 Feb 2018 21:45:06 GMT < Connection: close < Content-Length: 311 < <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>Bad Request</TITLE> <META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD> <BODY><h2>Bad Request</h2> <hr><p>HTTP Error 400. The request is badly formed.</p> </BODY></HTML> * Closing connection #0
I am not sure what’s going wrong. How do I solve the issue and pull the data with CURL ?
Any help would be appreciated. Thank you.