1. POST 上传(带 JSON 参数)
upload-mp3.sh
#!/bin/sh
if [ $# != 1 ]; then
echo "Parameter error."
exit 1
fi
# 进入流行歌曲目录
cd $1
curDir=${PWD##*/}
echo '>>> Current directory:' $curDir
output=""
filelist="ls *.mp3"
for file in $filelist
do
#echo ${file}
if [ ${file} == "ls" ];then
continue
fi
output=${output}\"${file}\",
done
# 打印出流行歌曲目录下的所有音乐文件
echo "file_list:"
echo "[${output%?}]"
# 上传目录下的所有歌曲名称
curl -X POST http://127.0.0.1:8080/mp3 -H "Content-Type: application/json" -d "{
\"type\":\"流行歌曲\",
\"list\":[{
\"name\":${curDir},
\"content\":[${output%?}]
}]}"
执行 upload-mp3.sh mydir,此脚本会读取当前目录下的子目录 mydir 里的所有 mp3 文件,然后组织成数组格式,再通过 POST 请求,以 JSON 格式发送到服务器上。