With curl, how can I pass multiple command line parameters in a POST?

I have the following controller:

public IActionResult Post([FromQuery] int Width, [FromQuery] int Height, [FromForm] IFormFile Image)

With Insomnia / Postman, I can do a post command and pass the width / height parameters in the url.

I am trying to do the same with CURL but the second parameter is not seen. In this case, height will be 0

curl -F image=@photo.jpg test/thumbnail?width=320&height=240

In that case, width will be 0

curl -F image=@photo.jpg test/thumbnail?height=240&width=320

What am I missing?

3

2 Answers

The most likely problem is that & is a special character in your macOS shell (the command-line interpreter); if left unquoted, it acts as a command separator and runs the preceding command in background. The rest (height=240) is interpreted as a second command by macOS.

So the parameter with & must be quoted, or the & itself escaped with a backslash:

"test/thumbnail?height=240&width=320"
test/thumbnail?height=240\&width=320
test/thumbnail?height=240"&"width=320
test/thumbnail?'height=240&width=320'
etc.

(? is also special in that it's a wildcard, but that's only a problem if it happens to match a real filename on the local system.)

The comments suggesting -d aren't correct. For one, they send parameters as POST payload – but the controller wants query-string (GET) parameters, which isn't the same thing at all. For another, the request can only use one format at a time – you cannot mix -F and -d in the same request.

1

for Mac OS the correct one would be

curl -F image=@photo.jpg test/thumbnail?width=320**\&**height=240

In Mac, you have to escape &

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like