Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use curl with urls that contain brackets characters?

Tags:

curl

I'm having some trouble using curl for any URLs which contain square brackets.

For example:

$ curl 'http://example.org/?param[0]=true'
curl: (3) [globbing] bad range in column 27

How do I properly escape the square brackets so that curl will issue the request?

like image 576
orirawlings Avatar asked Jan 30 '15 14:01

orirawlings


People also ask

How do you use curly brackets in URL?

There is no escaping character in an URL Rewrite expression, but here is how you include curly bracket within an URL Rewrite expression. For closing } curly bracket you don't have do anything if the character is not nested in a another URL Rewrite expression; otherwise you need to use UrlDecode with %7D.

How do you pass brackets in URL?

Parentheses “()” may be used as such in the query part of URL (i.e., the part after “?”). It is allowable, but not necessary, to %-encode them, as “%28” and “%29”. Brackets “[]” shall be %-encoded, as “%5B” and “%5D”, in the query part.

Are braces allowed in URL?

As mentioned previously, curly braces are unsafe characters, and are not valid in URIs (see RFC 3986). For the purposes of API documentation, and other similar uses, they should not be percent encoded, however, because they still aren't URIs - they don't identify a resource.

What is curl Globbing?

curl offers "globbing" as a way to specify many URLs like that easily. The globbing uses the reserved symbols [] and {} for this, symbols that normally cannot be part of a legal URL (except for numerical IPv6 addresses but curl handles them fine anyway). If the globbing gets in your way, disable it with -g, --globoff .


1 Answers

It turns out that curl is trying to interpret the square brackets as a globbing pattern.

Luckily there is a curl option to turn the globbing behavior off:

$ curl -g 'http://example.org/?param[0]=true'
like image 191
orirawlings Avatar answered Sep 20 '22 12:09

orirawlings