What is the cURL command-line syntax to do a POST request?












2115















How can I make a POST request with the cURL command-line tool?










share|improve this question















migrated from stackoverflow.com Jun 6 '10 at 7:46


This question came from our site for professional and enthusiast programmers.























    2115















    How can I make a POST request with the cURL command-line tool?










    share|improve this question















    migrated from stackoverflow.com Jun 6 '10 at 7:46


    This question came from our site for professional and enthusiast programmers.





















      2115












      2115








      2115


      639






      How can I make a POST request with the cURL command-line tool?










      share|improve this question
















      How can I make a POST request with the cURL command-line tool?







      http curl






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 15 '15 at 2:54









      mic84

      2,30721817




      2,30721817










      asked Sep 17 '08 at 15:39







      Laurie Young











      migrated from stackoverflow.com Jun 6 '10 at 7:46


      This question came from our site for professional and enthusiast programmers.









      migrated from stackoverflow.com Jun 6 '10 at 7:46


      This question came from our site for professional and enthusiast programmers.
























          7 Answers
          7






          active

          oldest

          votes


















          2452





          +50









          With fields:



          curl --data "param1=value1&param2=value2" https://example.com/resource.cgi


          With fields specified individually:



          curl --data "param1=value1" --data "param2=value2" https://example.com/resource.cgi


          Multipart:



          curl --form "fileupload=@my-file.txt" https://example.com/resource.cgi


          Multipart with fields and a filename:



          curl --form "fileupload=@my-file.txt;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi


          Without data:



          curl --data '' https://example.com/resource.cgi

          curl -X POST https://example.com/resource.cgi

          curl --request POST https://example.com/resource.cgi


          For more information see the cURL manual. The cURL tutorial on emulating a web browser is helpful.



          With libcurl, use the curl_formadd() function to build your form before submitting it in the usual way. See the libcurl documentation for more information.



          For large files, consider adding parameters to show upload progress:



          curl --tr-encoding -X POST -v -# -o output -T filename.dat 
          http://example.com/resource.cgi


          The -o output is required, otherwise no progress bar will appear.






          share|improve this answer





















          • 7





            @LauriRanta --data-urlencode (no dash), in recent versions at least

            – waitinforatrain
            Feb 12 '13 at 12:34






          • 4





            Also works if you need to update a resource with a PUT: curl -X PUT ...

            – Subfuzion
            Jan 22 '14 at 4:38






          • 3





            I'm having trouble understanding... when would I do it With Fields, when with Multipart and when Without Data?

            – CodyBugstein
            Sep 21 '14 at 11:05






          • 6





            Instead of --data you can use -d.

            – user35538
            Oct 9 '15 at 16:32











          • i have an array of fields. how can i do this?

            – ARUNBALAN NV
            Mar 9 '16 at 13:13



















          493














          For a RESTful HTTP POST containing XML:




          curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:text/xml"




          or for JSON, use this:




          curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:application/json"




          This will read the contents of the file named filename.txt and send it as the post request.






          share|improve this answer





















          • 12





            @tom-wijsman explanation: curl -X POST implies an HTTP POST request, the -d parameter (long version: --data) tells curl that what follows will be POST parameters, and @filename designates the contents of the file filename as parameter. This approach works best with RESTful HTTP APIs as found at Twitter, Facebook, various other web services including Ruby on Rails as well as HTTP APIs of databases such as CouchDB. REST stands for Representational state transfer

            – soundmonster
            Jun 27 '12 at 11:27











          • How can we see response xml not in one line but formatted?

            – Vitaly Zdanevich
            Jul 29 '16 at 13:12






          • 3





            I think that you can leave off the -X POST since that is implied by -d.

            – benjifisher
            Nov 30 '16 at 19:02











          • How to give multiple headers?

            – keya
            May 29 '17 at 11:37











          • Multiple Headers: curl -H "header2:1" -H "header2:2" ...

            – Tomáš Kratochvíla
            Sep 8 '17 at 14:57



















          123














          Data from stdin with -d @-



          Example:



          echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown


          Output:



          <p>Hello <strong>world</strong>!</p>





          share|improve this answer





















          • 5





            Great if you have a JSON object already in clipboard

            – Luca Steeb
            May 29 '16 at 16:12











          • even better: echo "$message" | curl -H "Content-Type: application/json" -d @- "$url"

            – rzr
            Nov 8 '17 at 18:43



















          65














          curl -d "name=Rafael%20Sagula&phone=3320780" http://www.where.com/guest.cgi 


          is the example found in the Curl Example Manual.



          Use %26 for the ampersands though if the above doesn't work:



          curl -d "name=Rafael%20Sagula%26phone=3320780" http://www.where.com/guest.cgi 





          share|improve this answer

































            58














            If you want to login to a site, do the following:



            curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
            curl -L -b headers http://localhost/


            The first request saves the session cookie (that is provided upon successful login) in the "headers" file. From now on you can use that cookie to authenticate you to any part of the website that you usually access after logging in with a browser.






            share|improve this answer



















            • 4





              a note from curl's man page: 'The -c, --cookie-jar option is however a better way to store cookies.'

              – maxschlepzig
              Dec 28 '13 at 15:14



















            32














            curl -v --data-ascii var=value http://example.com


            and there are many more options, check curl --help for more information.






            share|improve this answer

































              20














              If you are lazy, you can get google-chrome to do all the work for you.




              1. Right-click the form you want to submit and select Inspect. This will open the DevTools panel.

              2. Select the Network tab in devtools and tick the Preserve log checkbox.

              3. Submit the form and locate the entry with method POST (right-click on any column header and make sure Method is checked).

              4. Right click the line with POST, and select Copy > Copy as cURL.


              chrome devtools: copy as cURL



              Chrome will copy all the request data in cURL syntax.



              Chrome uses --data 'param1=hello&param2=world' which you can make more readable by using a single -d or -F per parameter depending on which type of POST request you want to send, which can be either application/x-www-form-urlencoded or multipart/form-data accordingly.



              This will be POST-ed as application/x-www-form-urlencoded (used for the majority of forms that don't contain file uploads):





              curl http://httpbin.org/post 
              -H "User-Agent: Mozilla/2.2"
              -d param1=hello
              -d name=dinsdale


              For a multipart/form-data POST use -F (typically used with forms that contain file uploads, or where order of fields is important, or where multiple fields with the same name are required):



              curl http://httpbin.org/post 
              -H "User-Agent: Mozilla/2.2"
              -F param1=hello
              -F name=dinsdale
              -F name=piranha


              The User-Agent header is not normally needed, but I've thrown it in just in case. You can avoid having to set the user agent on every request by creating the ~/.curlrc file which contains e.g. User-Agent: "Mozilla/2.2"






              share|improve this answer































                7 Answers
                7






                active

                oldest

                votes








                7 Answers
                7






                active

                oldest

                votes









                active

                oldest

                votes






                active

                oldest

                votes









                2452





                +50









                With fields:



                curl --data "param1=value1&param2=value2" https://example.com/resource.cgi


                With fields specified individually:



                curl --data "param1=value1" --data "param2=value2" https://example.com/resource.cgi


                Multipart:



                curl --form "fileupload=@my-file.txt" https://example.com/resource.cgi


                Multipart with fields and a filename:



                curl --form "fileupload=@my-file.txt;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi


                Without data:



                curl --data '' https://example.com/resource.cgi

                curl -X POST https://example.com/resource.cgi

                curl --request POST https://example.com/resource.cgi


                For more information see the cURL manual. The cURL tutorial on emulating a web browser is helpful.



                With libcurl, use the curl_formadd() function to build your form before submitting it in the usual way. See the libcurl documentation for more information.



                For large files, consider adding parameters to show upload progress:



                curl --tr-encoding -X POST -v -# -o output -T filename.dat 
                http://example.com/resource.cgi


                The -o output is required, otherwise no progress bar will appear.






                share|improve this answer





















                • 7





                  @LauriRanta --data-urlencode (no dash), in recent versions at least

                  – waitinforatrain
                  Feb 12 '13 at 12:34






                • 4





                  Also works if you need to update a resource with a PUT: curl -X PUT ...

                  – Subfuzion
                  Jan 22 '14 at 4:38






                • 3





                  I'm having trouble understanding... when would I do it With Fields, when with Multipart and when Without Data?

                  – CodyBugstein
                  Sep 21 '14 at 11:05






                • 6





                  Instead of --data you can use -d.

                  – user35538
                  Oct 9 '15 at 16:32











                • i have an array of fields. how can i do this?

                  – ARUNBALAN NV
                  Mar 9 '16 at 13:13
















                2452





                +50









                With fields:



                curl --data "param1=value1&param2=value2" https://example.com/resource.cgi


                With fields specified individually:



                curl --data "param1=value1" --data "param2=value2" https://example.com/resource.cgi


                Multipart:



                curl --form "fileupload=@my-file.txt" https://example.com/resource.cgi


                Multipart with fields and a filename:



                curl --form "fileupload=@my-file.txt;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi


                Without data:



                curl --data '' https://example.com/resource.cgi

                curl -X POST https://example.com/resource.cgi

                curl --request POST https://example.com/resource.cgi


                For more information see the cURL manual. The cURL tutorial on emulating a web browser is helpful.



                With libcurl, use the curl_formadd() function to build your form before submitting it in the usual way. See the libcurl documentation for more information.



                For large files, consider adding parameters to show upload progress:



                curl --tr-encoding -X POST -v -# -o output -T filename.dat 
                http://example.com/resource.cgi


                The -o output is required, otherwise no progress bar will appear.






                share|improve this answer





















                • 7





                  @LauriRanta --data-urlencode (no dash), in recent versions at least

                  – waitinforatrain
                  Feb 12 '13 at 12:34






                • 4





                  Also works if you need to update a resource with a PUT: curl -X PUT ...

                  – Subfuzion
                  Jan 22 '14 at 4:38






                • 3





                  I'm having trouble understanding... when would I do it With Fields, when with Multipart and when Without Data?

                  – CodyBugstein
                  Sep 21 '14 at 11:05






                • 6





                  Instead of --data you can use -d.

                  – user35538
                  Oct 9 '15 at 16:32











                • i have an array of fields. how can i do this?

                  – ARUNBALAN NV
                  Mar 9 '16 at 13:13














                2452





                +50







                2452





                +50



                2452




                +50





                With fields:



                curl --data "param1=value1&param2=value2" https://example.com/resource.cgi


                With fields specified individually:



                curl --data "param1=value1" --data "param2=value2" https://example.com/resource.cgi


                Multipart:



                curl --form "fileupload=@my-file.txt" https://example.com/resource.cgi


                Multipart with fields and a filename:



                curl --form "fileupload=@my-file.txt;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi


                Without data:



                curl --data '' https://example.com/resource.cgi

                curl -X POST https://example.com/resource.cgi

                curl --request POST https://example.com/resource.cgi


                For more information see the cURL manual. The cURL tutorial on emulating a web browser is helpful.



                With libcurl, use the curl_formadd() function to build your form before submitting it in the usual way. See the libcurl documentation for more information.



                For large files, consider adding parameters to show upload progress:



                curl --tr-encoding -X POST -v -# -o output -T filename.dat 
                http://example.com/resource.cgi


                The -o output is required, otherwise no progress bar will appear.






                share|improve this answer















                With fields:



                curl --data "param1=value1&param2=value2" https://example.com/resource.cgi


                With fields specified individually:



                curl --data "param1=value1" --data "param2=value2" https://example.com/resource.cgi


                Multipart:



                curl --form "fileupload=@my-file.txt" https://example.com/resource.cgi


                Multipart with fields and a filename:



                curl --form "fileupload=@my-file.txt;filename=desired-filename.txt" --form param1=value1 --form param2=value2 https://example.com/resource.cgi


                Without data:



                curl --data '' https://example.com/resource.cgi

                curl -X POST https://example.com/resource.cgi

                curl --request POST https://example.com/resource.cgi


                For more information see the cURL manual. The cURL tutorial on emulating a web browser is helpful.



                With libcurl, use the curl_formadd() function to build your form before submitting it in the usual way. See the libcurl documentation for more information.



                For large files, consider adding parameters to show upload progress:



                curl --tr-encoding -X POST -v -# -o output -T filename.dat 
                http://example.com/resource.cgi


                The -o output is required, otherwise no progress bar will appear.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Dec 2 '17 at 11:40









                Chris Stryczynski

                1176




                1176










                answered Sep 17 '08 at 15:43









                Stephen DekenStephen Deken

                24.7k117




                24.7k117








                • 7





                  @LauriRanta --data-urlencode (no dash), in recent versions at least

                  – waitinforatrain
                  Feb 12 '13 at 12:34






                • 4





                  Also works if you need to update a resource with a PUT: curl -X PUT ...

                  – Subfuzion
                  Jan 22 '14 at 4:38






                • 3





                  I'm having trouble understanding... when would I do it With Fields, when with Multipart and when Without Data?

                  – CodyBugstein
                  Sep 21 '14 at 11:05






                • 6





                  Instead of --data you can use -d.

                  – user35538
                  Oct 9 '15 at 16:32











                • i have an array of fields. how can i do this?

                  – ARUNBALAN NV
                  Mar 9 '16 at 13:13














                • 7





                  @LauriRanta --data-urlencode (no dash), in recent versions at least

                  – waitinforatrain
                  Feb 12 '13 at 12:34






                • 4





                  Also works if you need to update a resource with a PUT: curl -X PUT ...

                  – Subfuzion
                  Jan 22 '14 at 4:38






                • 3





                  I'm having trouble understanding... when would I do it With Fields, when with Multipart and when Without Data?

                  – CodyBugstein
                  Sep 21 '14 at 11:05






                • 6





                  Instead of --data you can use -d.

                  – user35538
                  Oct 9 '15 at 16:32











                • i have an array of fields. how can i do this?

                  – ARUNBALAN NV
                  Mar 9 '16 at 13:13








                7




                7





                @LauriRanta --data-urlencode (no dash), in recent versions at least

                – waitinforatrain
                Feb 12 '13 at 12:34





                @LauriRanta --data-urlencode (no dash), in recent versions at least

                – waitinforatrain
                Feb 12 '13 at 12:34




                4




                4





                Also works if you need to update a resource with a PUT: curl -X PUT ...

                – Subfuzion
                Jan 22 '14 at 4:38





                Also works if you need to update a resource with a PUT: curl -X PUT ...

                – Subfuzion
                Jan 22 '14 at 4:38




                3




                3





                I'm having trouble understanding... when would I do it With Fields, when with Multipart and when Without Data?

                – CodyBugstein
                Sep 21 '14 at 11:05





                I'm having trouble understanding... when would I do it With Fields, when with Multipart and when Without Data?

                – CodyBugstein
                Sep 21 '14 at 11:05




                6




                6





                Instead of --data you can use -d.

                – user35538
                Oct 9 '15 at 16:32





                Instead of --data you can use -d.

                – user35538
                Oct 9 '15 at 16:32













                i have an array of fields. how can i do this?

                – ARUNBALAN NV
                Mar 9 '16 at 13:13





                i have an array of fields. how can i do this?

                – ARUNBALAN NV
                Mar 9 '16 at 13:13













                493














                For a RESTful HTTP POST containing XML:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:text/xml"




                or for JSON, use this:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:application/json"




                This will read the contents of the file named filename.txt and send it as the post request.






                share|improve this answer





















                • 12





                  @tom-wijsman explanation: curl -X POST implies an HTTP POST request, the -d parameter (long version: --data) tells curl that what follows will be POST parameters, and @filename designates the contents of the file filename as parameter. This approach works best with RESTful HTTP APIs as found at Twitter, Facebook, various other web services including Ruby on Rails as well as HTTP APIs of databases such as CouchDB. REST stands for Representational state transfer

                  – soundmonster
                  Jun 27 '12 at 11:27











                • How can we see response xml not in one line but formatted?

                  – Vitaly Zdanevich
                  Jul 29 '16 at 13:12






                • 3





                  I think that you can leave off the -X POST since that is implied by -d.

                  – benjifisher
                  Nov 30 '16 at 19:02











                • How to give multiple headers?

                  – keya
                  May 29 '17 at 11:37











                • Multiple Headers: curl -H "header2:1" -H "header2:2" ...

                  – Tomáš Kratochvíla
                  Sep 8 '17 at 14:57
















                493














                For a RESTful HTTP POST containing XML:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:text/xml"




                or for JSON, use this:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:application/json"




                This will read the contents of the file named filename.txt and send it as the post request.






                share|improve this answer





















                • 12





                  @tom-wijsman explanation: curl -X POST implies an HTTP POST request, the -d parameter (long version: --data) tells curl that what follows will be POST parameters, and @filename designates the contents of the file filename as parameter. This approach works best with RESTful HTTP APIs as found at Twitter, Facebook, various other web services including Ruby on Rails as well as HTTP APIs of databases such as CouchDB. REST stands for Representational state transfer

                  – soundmonster
                  Jun 27 '12 at 11:27











                • How can we see response xml not in one line but formatted?

                  – Vitaly Zdanevich
                  Jul 29 '16 at 13:12






                • 3





                  I think that you can leave off the -X POST since that is implied by -d.

                  – benjifisher
                  Nov 30 '16 at 19:02











                • How to give multiple headers?

                  – keya
                  May 29 '17 at 11:37











                • Multiple Headers: curl -H "header2:1" -H "header2:2" ...

                  – Tomáš Kratochvíla
                  Sep 8 '17 at 14:57














                493












                493








                493







                For a RESTful HTTP POST containing XML:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:text/xml"




                or for JSON, use this:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:application/json"




                This will read the contents of the file named filename.txt and send it as the post request.






                share|improve this answer















                For a RESTful HTTP POST containing XML:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:text/xml"




                or for JSON, use this:




                curl -X POST -d @filename.txt http://example.com/path/to/resource --header "Content-Type:application/json"




                This will read the contents of the file named filename.txt and send it as the post request.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 4 '14 at 20:08









                pauldendulk

                1033




                1033










                answered Mar 10 '11 at 8:29









                soundmonstersoundmonster

                5,031194




                5,031194








                • 12





                  @tom-wijsman explanation: curl -X POST implies an HTTP POST request, the -d parameter (long version: --data) tells curl that what follows will be POST parameters, and @filename designates the contents of the file filename as parameter. This approach works best with RESTful HTTP APIs as found at Twitter, Facebook, various other web services including Ruby on Rails as well as HTTP APIs of databases such as CouchDB. REST stands for Representational state transfer

                  – soundmonster
                  Jun 27 '12 at 11:27











                • How can we see response xml not in one line but formatted?

                  – Vitaly Zdanevich
                  Jul 29 '16 at 13:12






                • 3





                  I think that you can leave off the -X POST since that is implied by -d.

                  – benjifisher
                  Nov 30 '16 at 19:02











                • How to give multiple headers?

                  – keya
                  May 29 '17 at 11:37











                • Multiple Headers: curl -H "header2:1" -H "header2:2" ...

                  – Tomáš Kratochvíla
                  Sep 8 '17 at 14:57














                • 12





                  @tom-wijsman explanation: curl -X POST implies an HTTP POST request, the -d parameter (long version: --data) tells curl that what follows will be POST parameters, and @filename designates the contents of the file filename as parameter. This approach works best with RESTful HTTP APIs as found at Twitter, Facebook, various other web services including Ruby on Rails as well as HTTP APIs of databases such as CouchDB. REST stands for Representational state transfer

                  – soundmonster
                  Jun 27 '12 at 11:27











                • How can we see response xml not in one line but formatted?

                  – Vitaly Zdanevich
                  Jul 29 '16 at 13:12






                • 3





                  I think that you can leave off the -X POST since that is implied by -d.

                  – benjifisher
                  Nov 30 '16 at 19:02











                • How to give multiple headers?

                  – keya
                  May 29 '17 at 11:37











                • Multiple Headers: curl -H "header2:1" -H "header2:2" ...

                  – Tomáš Kratochvíla
                  Sep 8 '17 at 14:57








                12




                12





                @tom-wijsman explanation: curl -X POST implies an HTTP POST request, the -d parameter (long version: --data) tells curl that what follows will be POST parameters, and @filename designates the contents of the file filename as parameter. This approach works best with RESTful HTTP APIs as found at Twitter, Facebook, various other web services including Ruby on Rails as well as HTTP APIs of databases such as CouchDB. REST stands for Representational state transfer

                – soundmonster
                Jun 27 '12 at 11:27





                @tom-wijsman explanation: curl -X POST implies an HTTP POST request, the -d parameter (long version: --data) tells curl that what follows will be POST parameters, and @filename designates the contents of the file filename as parameter. This approach works best with RESTful HTTP APIs as found at Twitter, Facebook, various other web services including Ruby on Rails as well as HTTP APIs of databases such as CouchDB. REST stands for Representational state transfer

                – soundmonster
                Jun 27 '12 at 11:27













                How can we see response xml not in one line but formatted?

                – Vitaly Zdanevich
                Jul 29 '16 at 13:12





                How can we see response xml not in one line but formatted?

                – Vitaly Zdanevich
                Jul 29 '16 at 13:12




                3




                3





                I think that you can leave off the -X POST since that is implied by -d.

                – benjifisher
                Nov 30 '16 at 19:02





                I think that you can leave off the -X POST since that is implied by -d.

                – benjifisher
                Nov 30 '16 at 19:02













                How to give multiple headers?

                – keya
                May 29 '17 at 11:37





                How to give multiple headers?

                – keya
                May 29 '17 at 11:37













                Multiple Headers: curl -H "header2:1" -H "header2:2" ...

                – Tomáš Kratochvíla
                Sep 8 '17 at 14:57





                Multiple Headers: curl -H "header2:1" -H "header2:2" ...

                – Tomáš Kratochvíla
                Sep 8 '17 at 14:57











                123














                Data from stdin with -d @-



                Example:



                echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown


                Output:



                <p>Hello <strong>world</strong>!</p>





                share|improve this answer





















                • 5





                  Great if you have a JSON object already in clipboard

                  – Luca Steeb
                  May 29 '16 at 16:12











                • even better: echo "$message" | curl -H "Content-Type: application/json" -d @- "$url"

                  – rzr
                  Nov 8 '17 at 18:43
















                123














                Data from stdin with -d @-



                Example:



                echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown


                Output:



                <p>Hello <strong>world</strong>!</p>





                share|improve this answer





















                • 5





                  Great if you have a JSON object already in clipboard

                  – Luca Steeb
                  May 29 '16 at 16:12











                • even better: echo "$message" | curl -H "Content-Type: application/json" -d @- "$url"

                  – rzr
                  Nov 8 '17 at 18:43














                123












                123








                123







                Data from stdin with -d @-



                Example:



                echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown


                Output:



                <p>Hello <strong>world</strong>!</p>





                share|improve this answer















                Data from stdin with -d @-



                Example:



                echo '{"text": "Hello **world**!"}' | curl -d @- https://api.github.com/markdown


                Output:



                <p>Hello <strong>world</strong>!</p>






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Jan 27 at 11:15

























                answered Mar 25 '14 at 19:35









                Ciro Santilli 新疆改造中心 六四事件 法轮功Ciro Santilli 新疆改造中心 六四事件 法轮功

                4,04622735




                4,04622735








                • 5





                  Great if you have a JSON object already in clipboard

                  – Luca Steeb
                  May 29 '16 at 16:12











                • even better: echo "$message" | curl -H "Content-Type: application/json" -d @- "$url"

                  – rzr
                  Nov 8 '17 at 18:43














                • 5





                  Great if you have a JSON object already in clipboard

                  – Luca Steeb
                  May 29 '16 at 16:12











                • even better: echo "$message" | curl -H "Content-Type: application/json" -d @- "$url"

                  – rzr
                  Nov 8 '17 at 18:43








                5




                5





                Great if you have a JSON object already in clipboard

                – Luca Steeb
                May 29 '16 at 16:12





                Great if you have a JSON object already in clipboard

                – Luca Steeb
                May 29 '16 at 16:12













                even better: echo "$message" | curl -H "Content-Type: application/json" -d @- "$url"

                – rzr
                Nov 8 '17 at 18:43





                even better: echo "$message" | curl -H "Content-Type: application/json" -d @- "$url"

                – rzr
                Nov 8 '17 at 18:43











                65














                curl -d "name=Rafael%20Sagula&phone=3320780" http://www.where.com/guest.cgi 


                is the example found in the Curl Example Manual.



                Use %26 for the ampersands though if the above doesn't work:



                curl -d "name=Rafael%20Sagula%26phone=3320780" http://www.where.com/guest.cgi 





                share|improve this answer






























                  65














                  curl -d "name=Rafael%20Sagula&phone=3320780" http://www.where.com/guest.cgi 


                  is the example found in the Curl Example Manual.



                  Use %26 for the ampersands though if the above doesn't work:



                  curl -d "name=Rafael%20Sagula%26phone=3320780" http://www.where.com/guest.cgi 





                  share|improve this answer




























                    65












                    65








                    65







                    curl -d "name=Rafael%20Sagula&phone=3320780" http://www.where.com/guest.cgi 


                    is the example found in the Curl Example Manual.



                    Use %26 for the ampersands though if the above doesn't work:



                    curl -d "name=Rafael%20Sagula%26phone=3320780" http://www.where.com/guest.cgi 





                    share|improve this answer















                    curl -d "name=Rafael%20Sagula&phone=3320780" http://www.where.com/guest.cgi 


                    is the example found in the Curl Example Manual.



                    Use %26 for the ampersands though if the above doesn't work:



                    curl -d "name=Rafael%20Sagula%26phone=3320780" http://www.where.com/guest.cgi 






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Mar 13 '14 at 12:01









                    Community

                    1




                    1










                    answered Sep 17 '08 at 15:42









                    Patrick DesjardinsPatrick Desjardins

                    1,24911521




                    1,24911521























                        58














                        If you want to login to a site, do the following:



                        curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
                        curl -L -b headers http://localhost/


                        The first request saves the session cookie (that is provided upon successful login) in the "headers" file. From now on you can use that cookie to authenticate you to any part of the website that you usually access after logging in with a browser.






                        share|improve this answer



















                        • 4





                          a note from curl's man page: 'The -c, --cookie-jar option is however a better way to store cookies.'

                          – maxschlepzig
                          Dec 28 '13 at 15:14
















                        58














                        If you want to login to a site, do the following:



                        curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
                        curl -L -b headers http://localhost/


                        The first request saves the session cookie (that is provided upon successful login) in the "headers" file. From now on you can use that cookie to authenticate you to any part of the website that you usually access after logging in with a browser.






                        share|improve this answer



















                        • 4





                          a note from curl's man page: 'The -c, --cookie-jar option is however a better way to store cookies.'

                          – maxschlepzig
                          Dec 28 '13 at 15:14














                        58












                        58








                        58







                        If you want to login to a site, do the following:



                        curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
                        curl -L -b headers http://localhost/


                        The first request saves the session cookie (that is provided upon successful login) in the "headers" file. From now on you can use that cookie to authenticate you to any part of the website that you usually access after logging in with a browser.






                        share|improve this answer













                        If you want to login to a site, do the following:



                        curl -d "username=admin&password=admin&submit=Login" --dump-header headers http://localhost/Login
                        curl -L -b headers http://localhost/


                        The first request saves the session cookie (that is provided upon successful login) in the "headers" file. From now on you can use that cookie to authenticate you to any part of the website that you usually access after logging in with a browser.







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Mar 4 '12 at 2:21









                        Martin KonecnyMartin Konecny

                        1,0771010




                        1,0771010








                        • 4





                          a note from curl's man page: 'The -c, --cookie-jar option is however a better way to store cookies.'

                          – maxschlepzig
                          Dec 28 '13 at 15:14














                        • 4





                          a note from curl's man page: 'The -c, --cookie-jar option is however a better way to store cookies.'

                          – maxschlepzig
                          Dec 28 '13 at 15:14








                        4




                        4





                        a note from curl's man page: 'The -c, --cookie-jar option is however a better way to store cookies.'

                        – maxschlepzig
                        Dec 28 '13 at 15:14





                        a note from curl's man page: 'The -c, --cookie-jar option is however a better way to store cookies.'

                        – maxschlepzig
                        Dec 28 '13 at 15:14











                        32














                        curl -v --data-ascii var=value http://example.com


                        and there are many more options, check curl --help for more information.






                        share|improve this answer






























                          32














                          curl -v --data-ascii var=value http://example.com


                          and there are many more options, check curl --help for more information.






                          share|improve this answer




























                            32












                            32








                            32







                            curl -v --data-ascii var=value http://example.com


                            and there are many more options, check curl --help for more information.






                            share|improve this answer















                            curl -v --data-ascii var=value http://example.com


                            and there are many more options, check curl --help for more information.







                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Nov 5 '11 at 1:36









                            Tom Wijsman

                            50.3k23164247




                            50.3k23164247










                            answered Sep 17 '08 at 15:43









                            Vinko VrsalovicVinko Vrsalovic

                            2,08111818




                            2,08111818























                                20














                                If you are lazy, you can get google-chrome to do all the work for you.




                                1. Right-click the form you want to submit and select Inspect. This will open the DevTools panel.

                                2. Select the Network tab in devtools and tick the Preserve log checkbox.

                                3. Submit the form and locate the entry with method POST (right-click on any column header and make sure Method is checked).

                                4. Right click the line with POST, and select Copy > Copy as cURL.


                                chrome devtools: copy as cURL



                                Chrome will copy all the request data in cURL syntax.



                                Chrome uses --data 'param1=hello&param2=world' which you can make more readable by using a single -d or -F per parameter depending on which type of POST request you want to send, which can be either application/x-www-form-urlencoded or multipart/form-data accordingly.



                                This will be POST-ed as application/x-www-form-urlencoded (used for the majority of forms that don't contain file uploads):





                                curl http://httpbin.org/post 
                                -H "User-Agent: Mozilla/2.2"
                                -d param1=hello
                                -d name=dinsdale


                                For a multipart/form-data POST use -F (typically used with forms that contain file uploads, or where order of fields is important, or where multiple fields with the same name are required):



                                curl http://httpbin.org/post 
                                -H "User-Agent: Mozilla/2.2"
                                -F param1=hello
                                -F name=dinsdale
                                -F name=piranha


                                The User-Agent header is not normally needed, but I've thrown it in just in case. You can avoid having to set the user agent on every request by creating the ~/.curlrc file which contains e.g. User-Agent: "Mozilla/2.2"






                                share|improve this answer






























                                  20














                                  If you are lazy, you can get google-chrome to do all the work for you.




                                  1. Right-click the form you want to submit and select Inspect. This will open the DevTools panel.

                                  2. Select the Network tab in devtools and tick the Preserve log checkbox.

                                  3. Submit the form and locate the entry with method POST (right-click on any column header and make sure Method is checked).

                                  4. Right click the line with POST, and select Copy > Copy as cURL.


                                  chrome devtools: copy as cURL



                                  Chrome will copy all the request data in cURL syntax.



                                  Chrome uses --data 'param1=hello&param2=world' which you can make more readable by using a single -d or -F per parameter depending on which type of POST request you want to send, which can be either application/x-www-form-urlencoded or multipart/form-data accordingly.



                                  This will be POST-ed as application/x-www-form-urlencoded (used for the majority of forms that don't contain file uploads):





                                  curl http://httpbin.org/post 
                                  -H "User-Agent: Mozilla/2.2"
                                  -d param1=hello
                                  -d name=dinsdale


                                  For a multipart/form-data POST use -F (typically used with forms that contain file uploads, or where order of fields is important, or where multiple fields with the same name are required):



                                  curl http://httpbin.org/post 
                                  -H "User-Agent: Mozilla/2.2"
                                  -F param1=hello
                                  -F name=dinsdale
                                  -F name=piranha


                                  The User-Agent header is not normally needed, but I've thrown it in just in case. You can avoid having to set the user agent on every request by creating the ~/.curlrc file which contains e.g. User-Agent: "Mozilla/2.2"






                                  share|improve this answer




























                                    20












                                    20








                                    20







                                    If you are lazy, you can get google-chrome to do all the work for you.




                                    1. Right-click the form you want to submit and select Inspect. This will open the DevTools panel.

                                    2. Select the Network tab in devtools and tick the Preserve log checkbox.

                                    3. Submit the form and locate the entry with method POST (right-click on any column header and make sure Method is checked).

                                    4. Right click the line with POST, and select Copy > Copy as cURL.


                                    chrome devtools: copy as cURL



                                    Chrome will copy all the request data in cURL syntax.



                                    Chrome uses --data 'param1=hello&param2=world' which you can make more readable by using a single -d or -F per parameter depending on which type of POST request you want to send, which can be either application/x-www-form-urlencoded or multipart/form-data accordingly.



                                    This will be POST-ed as application/x-www-form-urlencoded (used for the majority of forms that don't contain file uploads):





                                    curl http://httpbin.org/post 
                                    -H "User-Agent: Mozilla/2.2"
                                    -d param1=hello
                                    -d name=dinsdale


                                    For a multipart/form-data POST use -F (typically used with forms that contain file uploads, or where order of fields is important, or where multiple fields with the same name are required):



                                    curl http://httpbin.org/post 
                                    -H "User-Agent: Mozilla/2.2"
                                    -F param1=hello
                                    -F name=dinsdale
                                    -F name=piranha


                                    The User-Agent header is not normally needed, but I've thrown it in just in case. You can avoid having to set the user agent on every request by creating the ~/.curlrc file which contains e.g. User-Agent: "Mozilla/2.2"






                                    share|improve this answer















                                    If you are lazy, you can get google-chrome to do all the work for you.




                                    1. Right-click the form you want to submit and select Inspect. This will open the DevTools panel.

                                    2. Select the Network tab in devtools and tick the Preserve log checkbox.

                                    3. Submit the form and locate the entry with method POST (right-click on any column header and make sure Method is checked).

                                    4. Right click the line with POST, and select Copy > Copy as cURL.


                                    chrome devtools: copy as cURL



                                    Chrome will copy all the request data in cURL syntax.



                                    Chrome uses --data 'param1=hello&param2=world' which you can make more readable by using a single -d or -F per parameter depending on which type of POST request you want to send, which can be either application/x-www-form-urlencoded or multipart/form-data accordingly.



                                    This will be POST-ed as application/x-www-form-urlencoded (used for the majority of forms that don't contain file uploads):





                                    curl http://httpbin.org/post 
                                    -H "User-Agent: Mozilla/2.2"
                                    -d param1=hello
                                    -d name=dinsdale


                                    For a multipart/form-data POST use -F (typically used with forms that contain file uploads, or where order of fields is important, or where multiple fields with the same name are required):



                                    curl http://httpbin.org/post 
                                    -H "User-Agent: Mozilla/2.2"
                                    -F param1=hello
                                    -F name=dinsdale
                                    -F name=piranha


                                    The User-Agent header is not normally needed, but I've thrown it in just in case. You can avoid having to set the user agent on every request by creating the ~/.curlrc file which contains e.g. User-Agent: "Mozilla/2.2"







                                    share|improve this answer














                                    share|improve this answer



                                    share|improve this answer








                                    edited Jun 10 '18 at 10:49

























                                    answered Sep 29 '17 at 8:06









                                    ccpizzaccpizza

                                    3,89933241




                                    3,89933241















                                        Popular posts from this blog

                                        How do I know what Microsoft account the skydrive app is syncing to?

                                        Grease: Live!

                                        When does type information flow backwards in C++?