Quantcast
Channel: Bashタグが付けられた新着記事 - Qiita
Viewing all articles
Browse latest Browse all 2806

Bash ShellScript で入れ子状の JSON データを HTTP POST する

$
0
0
概要 やや複雑な JSON データの HTTP POST 操作を Bash ShellScript で実施する方法. 詳細 下記 Python コード相当の処理を Bash ShellScript で実施する. -*- coding: utf-8 -*- import requests payload = { "authors":"やなせたかし", "book":[ { "title": "あんぱんまんとばいきんまん", "price": 935 }, { "title": "あんぱんまんとうみのあくま", "price": 935 } ] } requests.post("http://<IP>:<PORT>/api/v1/admin/", payload) Bash ShellScript コード #!/bin/bash H="Content-Type: application/json" payload=$(< <(cat <<EOF { "authors":"やなせたかし", "book":[ { "title": "あんぱんまんとばいきんまん", "price": 935 }, { "title": "あんぱんまんとうみのあくま", "price": 935 } ] } EOF )) curl -i -X POST -H "$H" -d "$payload" http://<IP>:<PORT>/api/v1/admin/   以上.

Viewing all articles
Browse latest Browse all 2806

Trending Articles