0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

curl 複数リクエスト送る際にパラメータをテキストファイルからセットする

Posted at

curlでテストデータを100件くらい作る必要が出てきて、簡単なスクリプトを作ったのでメモ

手順1:タブ区切りのパラメータがセットされたファイルを用意する。

ファイル例

param.tsv
00001  和食
00002  洋食
00003  イタリアン
・
・

手順2

curl.sh
# !/bin/bash

# 環境変数IFSで区切り文字をタブにセット
IFS="$(echo -e '\t')"
while read line
do
# array=()の構文でsplitedにテキストファイルをタブ区切りの配列を入れてます。
  splited=($line)

# あとはcurlするパラメータに指定してあげるだけ
  curl --location --request POST 'https://xxx/xxx' \
    --form genreId=${splited[0]} \
    --form genreName=${splited[1]} \
    --form 'remarks="テストデータ"' \
done < param.csv

値を連番にするだけでいい時は、テキストファイルから読まなくてもloopで回してインクリメントとかでも良い。
今回の例のようにマスタにもとづいたもので単純にインクリメントで生成できない場合にはテキストファイルから読み込ませると良いかも。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?