2

I want to do something like following:

curl localhost:8080/myapp/?params={"first_key":"I'm the first value","second_key":"the second value"}

This is working pretty normal when I am trying to access the page via browser, but it does not work via cURL. What am I doing wrong?

1

1 Answer 1

5

The issue is caused by cURL's "URL globbing parser" (see the docs):

You can specify multiple URLs or parts of URLs by writing part sets within braces as in:

http://{one,two,three}.com

So your command is being expanded to:

curl localhost:8080/myapp/?params="first_key":"I'm the first value"
curl localhost:8080/myapp/?params="second_key":"the second value"

You need to use the -g option (or --globoff):

This option switches off the "URL globbing parser". When you set this option, you can specify URLs that contain the letters {}[] without having them being interpreted by curl itself.

So:

curl -g localhost:8080/myapp/?params={"first_key":"I'm the first value","second_key":"the second value"}

Then, to preserve the double quotes, you need to wrap the URL in single quotes:

curl -g 'localhost:8080/myapp/?params={"first_key":"I'\''m the first value","second_key":"the second value"}'
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.