Reputation: 321
I execute a request of this kind:
curl http://127.0.0.1:8000/api/v1/landing?param1=1¶m2=2
As a result, I get only the first parameter. Why is this happening and how to fix it?
Upvotes: 4
Views: 8568
Reputation: 371
When you pass several parameters through curl in get
request, the URL used in the curl get call must be within double-quotes.
Please Note: you need to pass the URL in double-quotes when using several parameters, however this is not the case when there is a single parameter.
Below are the reasons why :
&
to pass multiple values to your request parameters in this GET call/request.curl http://127.0.0.1:8000/api/v1/landing?param1=1¶m2=2
In the Linux/Unix environment, &
has a pre-defined interpretation. It is used to run any command in the background. So if &
is present after any text, then the text is interpreted as a command and & means to run this command in the background.
Any text after &
is treated as a new command. So your above Curl get request is interpreted by Linux as 2 separate commands:
i. curl http://127.0.0.1:8000/api/v1/landing?param1=1&
ii. param2=2
Solution : The solution to avoid this interpretation by Unix/Linux is to surround your url with double quotes "
curl "http://127.0.0.1:8000/api/v1/landing?param1=1¶m2=2"
This will help you pass multiple parameter values to your curl get request.
Upvotes: 2
Reputation: 58002
You must put the argument within quotes (double or single, depending on what you want and on what platform you use) so that the shell doesn't interpret the &
letter.
Like this:
curl "http://127.0.0.1:8000/api/v1/landing?param1=1¶m2=2"
Upvotes: 12