Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to curl with query string parameter in format of "filter[name]=foo"

Tags:

http

curl

Here is an api on my server:

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

this works well when I access it via browser, and it works well with the following two methods:

$ 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", ...}

Now I'm trying to do it with:

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

it fails with error code 3, which stands for "URL malformed. The syntax was not correct."

How should I specify the query string parameters in the url?

like image 289
vts Avatar asked Nov 01 '25 13:11

vts


1 Answers

The query string needs to be URL encoded so it has to look like this:

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

asciitable.com.

like image 60
drew010 Avatar answered Nov 03 '25 11:11

drew010