Skip to navigation
Curl command to send parameter via GET
28.01.26
curl command to send parameter via GET ``` curl -G --data "s=sv&t=de&v=Dessa" https://mtranslate.myridia.com ``` ``` curl -X GET 'https://mtranslate.myridia.com?s=sv&t=de&v=Dessa' ``` bash Copy curl "https://example.com/api?param1=value1%26param2=value2" Note: While this works, it's often less readable than simply quoting the URL. URL encoding is more important for characters that are required to be encoded in URLs (like spaces, which become %20). 3. Using --data-urlencode (for POST requests that should be GET): If you're accidentally using a POST request when you intend to use a GET request with parameters, and you're using the --data option, you can use --data-urlencode instead. This will automatically URL-encode the data and append it to the URL as GET parameters. bash Copy curl --data-urlencode "param1=value1¶m2=value2" https://example.com/api Important: This only works if the server is expecting a GET request. If the server requires a POST request, this won't work. Also, this is less common; usually, you'd use -G (see below) for this scenario. 4. Using -G (or --get) to Force a GET Request with --data: The -G or --get option tells curl to force a GET request, even if you're using the --data option. curl will then automatically append the data from --data to the URL as GET parameters. bash Copy curl -G --data "param1=value1¶m2=value2" https://example.com/api This is useful when you want to construct the GET parameters using the --data option for clarity. 5. Building the URL in a Variable: You can construct the URL in a variable and then pass the variable to curl. This can be helpful for complex URLs. Remember to quote the variable when you pass it to curl. bash Copy URL="https://example.com/api?param1=value1¶m2=value2" curl "$URL" If you need to build the URL dynamically with variables, use double quotes: Copy ```bash PARAM1="my_value" URL="https://example.com/api?param1=$PARAM1¶m2=value2" curl "$URL" ```
Reply
Anonymous
Information Epoch 1770133060
Programmer time is expensive, conserve it in preference to machine time.
Home
Notebook
Contact us