Frage

My Url is Like:

https://<ip:port>/TestRESTServices/objects/test-folder

JSON data that I want to pass is:

{
   "name":"test-1",
   "parent-uuid":"126"
}

test-1 is the folder name which i want to create. When i invoke this url with the data in Poster plugin in firefox via POST it works fine and folder test-1 is created.

 //using Content Type : "application/json"

How can I invoke/call this REST API using cURL ? Need Help.

This is what i tried:

 curl -i -H "Accept: application/json" -X POST -d '{"name":"test-1","parent-uuid":"126"}' https://<ip:port>/TestRESTServices/objects/test-folder

It throws an error that curl: (52) Empty reply from server

War es hilfreich?

Lösung

Unfortunately I don't have a REST API online to try it, but resources that I found suggest the following approaches:

curl -v -H "Content-Type: application/json" -X POST --data "@issue.json" -u login:password http://redmine/issues.json

where the issues.json is a file containing the JSON request.

Resources I found useful:

1, 2

Hope it helps!

For Authentication : Give the userid/password as admin:password

  TOKEN=$(curl -s -k -X POST --basic -u "admin:password" "{host}/TestAuthServices/auth/tokens" | sed -rn 's/\{"Token":"([^"]+)".+/\1/p')

After getting this token call curl as:

 curl -s -k -X POST -H "Content-Type: application/json" -H "Authorization: X-SAML ${TOKEN}" -d '{"name":"test","parent-uuid":"126"}' "{host}/TestRESTServices/objects/test-folder"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top