【发布时间】:2020-07-07 08:29:58
【问题描述】:
我一直在玩 api,我能够请求数据并解析 json 响应。 但是,我在请求中使用了变量,这些变量给了我问题。 如果变量不包含空格,那么一切都很好,但如果有空格,那么我会失败。
我就是这样做的
search="string with space"
curl -s 'https://apiurl.com' \
> -d 'search "'$search'";' \
> -H 'user-key: xxxxxxxxxxx' \
> -H 'Accept: application/json'
[
{
"title": "Syntax Error",
"status": 400,
"cause": "Mismatched input, double check your input. Common cause is sending \\\" instead of \"."
}
]
谁能解释为什么会这样? 如果我在请求中使用带空格的字符串,而不使用变量,那么它没有问题。
【问题讨论】:
-
试试
-d 'search "'"$search"'";' -
谢谢。那行得通。