curl -k -u jsmith:passw0rd
https://hostname:port/cli/component?active=true
-X GET
這個範例利用使用者名稱 jsmith 及密碼 passw0rd。在大多數情況下,請對要使用的 REST 指令建立專用使用者帳戶,並授與該帳戶適當的權限。
將伺服器的主機名稱及埠用於 hostname 和 port。 例如,如果主機名稱是 ucdeploy.example.org,並且埠是預設值 8443,則 curl 指令可能類似於下列範例:curl -k -u jsmith:passw0rd
https://ucdeploy.example.org:8443/cli/component?active=true
-X GET
此指令的回應是伺服器上所有作用中元件的 JSONArray 清單。如需此回應的範例,請參閱Get information about all components on the server。curl -k -u jsmith:passw0rd
"https://fit-vm13-108.rtp.raleigh.ibm.com:8443/cli/
version/getLink?component=JPetStore-APP
&version=1.0
&linkName=IBM%20web%20site"
在此情況下,會將每一個參數及值配對附加至 URL,置於問號 (?) 後面。
符號 (&) 會區隔每一個配對。因為 curl 是 Linux 指令,並且 & 符號在 Linux 指令行中具有特殊意義,所以將 URL(包括參數)放在引號中。{
"description": "Description",
"enforceCompleteSnapshots": "Specify true to require
an explicit version for each component",
"name": "Application name or ID",
"notificationScheme": "Notification scheme"
}
此範本列在指令的參考資訊中;請參閱 Create an application from a JSON file。{
"description": "My new application",
"enforceCompleteSnapshots": "false",
"name": "My Application",
"notificationScheme": "Default Notification Scheme"
}
如果要將此 JSON 字串傳遞至 application/create 資源,您可以將該字串儲存至檔案,或者將其包括在指令中。
例如,如果將該字串儲存至名為 newApplication.json 的檔案,則該指令將類似於下列範例:curl -k -u jsmith:passw0rd
https://fit-vm13-108.rtp.raleigh.ibm.com:8443/cli/application/create
-X PUT -d @newApplication.json
您還可以直接將字串傳遞至指令,如下列範例中所示:curl -k -u jsmith:passw0rd
https://fit-vm13-108.rtp.raleigh.ibm.com:8443/cli/application/create
-X PUT
-d {"description":"My new application",
"enforceCompleteSnapshots":"false",
"name":"My Application 67",
"notificationScheme":"Default Notification Scheme"}
有兩種主要方式用來取得指令的 JSON 字串範本。這些範本列在每一個指令的參考資訊中。您還可以帶 -t 選項來執行對等的指令行用戶端指令。 帶此選項執行 CLI 指令會列印 JSON 範本。
因為伺服器介面使用 REST API,所以您還可以照常登入伺服器,並監視 Web 應用程式產生的要求。您可以使用 Web 瀏覽器延伸或外部程式來監視這些要求。例如,如果要查看適用於 resource/create 資源之 PUT 方法的 JSON 字串,請照常在 Web 伺服器上建立資源,然後查看瀏覽器要求中的 JSON 字串,如下圖中所示。REST 指令的 JSON 字串與此字串相同或類似。
