HTTPリクエスト GET/POST
HTTPのGETをサーバーから情報を取得してきます。JSONファイルなどを返してくれる
HTTPのPOSTはサーバーに情報を送ります。特に返ってくるものはない(成功、失敗が返ってくることがある)
ダウンロード(GET)、アップロード(POST)が可能です。
ショートカット(iOS)
ショートカットとはWorkflowがAppleNi買収されiOS 12から利用可能になったiOS標準のアプリです。
実は多くのことができるのですが、今回はHTTPのGET/POSTをやっていきます。
cURL
「curl」コマンドは、さまざまなプロトコルに対応したデータを転送するためのコマンドです。
HTTP GET
cURL
curl -X GET "https://example.com/api/" -H "accept: application/json" -H "Content-Type: form"
ショートカット
使用するショートカットのアクションはURLの内容を取得
です。
方法をGET
にすることでHTTPのGETが利用可能です。
cURLの「-H」header
はヘッダ
から設定可能です。
HTTP POST
cURL
curl -X POST "https://example.com/api/" -H "accept: application/json" -d "temperature=18" -d "operation_mode=auto"
ショートカット
使用するショートカットのアクションはURLの内容を取得
です。
方法をPOST
にすることでHTTPのPOSTが利用可能です。
cURLの「-d」data
は本文を要求
のフォーム
から設定可能です。