Curl:无法使用 riak 解析主机

Curl: could not resolve host using riak

我有这个 bash 脚本,我用它来读取 csv 文件并将我的数据插入 riak。

#!/bin/bash
# Set "," as the field separator using $IFS 
# and read line by line using while read combo 
while IFS=',' read -r Num_Acc senc catv occutc obs obsm choc manv num_veh
do
eval curl -i -X POST http://127.0.0.1:8098/riak/vehicule -H "Content-Type:application/json" -d {"Num_Acc":"$Num_Acc","senc":$senc,"catv":"$catv","occutc":"$occutc","obs":"$obs","obsm":$obsm,"choc":$choc,"manv":"$manv","num_veh":"$num_veh"}
done < vehicules_2016.csv

问题是我有这个错误,我不知道它可能来自哪里:

curl: (6) Could not resolve host: senc
curl: (6) Could not resolve host: catv
curl: (6) Could not resolve host: occutc
curl: (6) Could not resolve host: obs
curl: (6) Could not resolve host: obsm
curl: (6) Could not resolve host: choc
curl: (6) Could not resolve host: manv
curl: (3) Illegal characters found in URL
HTTP/1.1 201 Created
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.10.9 (cafe not found)
Location: /riak/vehicule/NiuPBkgCFBaqUNhorovnBvix2ED
Date: Mon, 13 Nov 2017 11:43:08 GMT
Content-Type: application/json
Content-Length: 0

我认为问题可能出在 json 语法上。

感谢您的帮助。

您必须将数据括在双引号 " 和转义内部双引号之间,例如 \" 或者您也可以使用 heredoc :

#!/bin/bash
while IFS=',' read -r Num_Acc senc catv occutc obs obsm choc manv num_veh
do
data=$(cat <<EOF
{
    "Num_Acc":"$Num_Acc",
    "senc": "$senc",
    "catv": "$catv",
    "occutc": "$occutc",
    "obs": "$obs",
    "obsm": "$obsm",
    "choc": "$choc",
    "manv": "$manv",
    "num_veh": "$num_veh"
}
EOF
)

curl -i http://127.0.0.1:8098/riak/vehicule \
     -H "Content-Type: application/json" \
     -d "$data"

done < vehicules_2016.csv

检查this post