curl -k -u jsmith:passw0rd
https://hostname:port/initiatives/
-X GET -H "Accept: application/json"
這個範例利用使用者名稱 jsmith 及密碼 passw0rd。在大多數情況下,請對要使用的 REST 指令建立專用使用者帳戶,並授與該帳戶適當的權限。
對於 hostname 和 port,使用伺服器的主機名稱和埠。例如,如果主機名稱是 ucrelease.example.org,埠是預設值 8080,則 curl 指令可能類似於下面的範例:curl -k -u jsmith:passw0rd
https://ucrelease.example.org:8080/initiatives/
-X GET -H "Accept: application/json"
此指令的回應是伺服器上所有提案的
JSONArray 清單,如下面的範例中所示:[
{
"description": "My init",
"name": "InitA",
"id": "c1e7dd8f-b1fc-41ea-8d73-a120da8d9999",
"version": 0,
"dateCreated": 1413559219120
},
{
"description": "Another init",
"name": "InitB",
"id": "30873ef0-c9f3-4af3-a4dd-eedda71c9bbf",
"version": 0,
"dateCreated": 1413559224354
}
]
curl -k -u jsmith:passw0rd
https://ucrelease.example.org:8080/initiatives/
c1e7dd8f-b1fc-41ea-8d73-a120da8d9999"
-X GET -H "Accept: application/json"
curl -k -u jsmith:passw0rd
https://ucrelease.example.org:8080/initiatives/
?format=detail
-X GET -H "Accept: application/json"
與省略該參數相比,產生的 JSON
程式碼的詳細程度較高。在此情況下,它包括與每一個提案相關聯的應用程式、發行和變更。如需
format 參數的有效值,請參閱該方法的參考頁面。{
"name": "Initiative name",
"description": "Initiative description"
}
此範本列在指令的參考資訊中。請參閱REST 指令。curl -k -u jsmith:passw0rd
https://ucrelease.example.org:8080/initiatives/
-d @newInitiative.json
-X POST -H "Content-Type: application/json"
您還可以將字串直接傳遞給指令,如下面的範例中所示:curl -k -u jsmith:passw0rd
https://ucrelease.example.org:8080/initiatives/
-d '{"name":"Initiative B","description":"Description of Initiative B"}'
-X POST -H "Content-Type: application/json"