【问题标题】:how to curl with query string parameter in format of "filter[name]=foo"如何使用“filter [name] = foo”格式的查询字符串参数卷曲
【发布时间】:2016-03-03 12:56:38
【问题描述】:

这是我服务器上的一个 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,代表“URL 格式错误。语法不正确。”

应该如何在url中指定查询字符串参数?

【问题讨论】:

  • 引用网址?

标签: http curl


【解决方案1】:

查询字符串必须是URL encoded,所以它必须看起来像这样:

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

asciitable.com.

【讨论】:

    猜你喜欢
    • 2019-05-15
    • 1970-01-01
    • 2013-08-09
    • 2013-04-10
    • 2021-09-24
    • 2017-04-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多