如何卷曲查询字符串参数的格式为" filter [name] = foo"

时间:2016-03-03 12:56:39

标签: http curl

这是我服务器上的api:

https://server/api/v1/products?filter[name]=foo

当我通过浏览器访问它时效果很好,并且它适用于以下两种方法:

$ cat /tmp/x
{"filter": {"name": "foo"}}

$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : -H 'Content-Type: application/json' -d "@/tmp/x" https://server/api/v1/products
{"name": "foo", ...}

$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : -d "filter[name]=foo" https://server/api/v1/products
{"name": "foo", ...}

现在我试图用:

$ curl -X GET -H 'Accept: application/json' -k -s --negotiate -u : https://server/api/v1/products?filter[name]=foo
$ echo $?
3

它失败,错误代码为3,代表"网址格式错误。语法不正确。"

如何在网址中指定查询字符串参数?

1 个答案:

答案 0 :(得分:3)

查询字符串必须为URL encoded,因此必须如下所示:

https://server/api/v1/products?filter%5Bname%5D=foo

asciitable.com