What Is The cURL Command-Line Syntax To Do A POST Request?
What Is The cURL Command-Line Syntax To Do A POST Request?
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
curl
Michael Durrant
364
Laurie Young
17
6 Answers
With fields:
curldata"param1=value1¶m2=value2"https://example.com/resource.cgi
Multipart:
curlform"[email protected]"https://example.com/resource.cgi
Without data:
curldata''https://example.com/resource.cgi
curlXPOSThttps://example.com/resource.cgi
curlrequestPOSThttps://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:
curltrencodingXPOSTv#ooutputTfilename.dat\
http://example.com/resource.cgi
14
2 @LauriRanta dataurlencode (no dash), in recent versions at least waitinforatrain Feb 12 '13 at 12:34
1 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 WithFields, when with Multipart and when
WithoutData? Imray Sep 21 '14 at 11:05
Instead of data you can use d. user35538 Oct 9 at 16:32
log in
tour
help
Sign up
This will read the contents of the file named filename.txt and send it as the post request.
edited Nov 4 '14 at 20:08
pauldendulk
soundmonster
103
3,481
3 Could you provide some explanation about what your code does? Tom Wijsman Nov 5 '11 at 1:36
6 @tom-wijsman explanation: curlXPOST 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
3 How is this more RESTful than other ways though? Niklas Berglund Oct 3 '12 at 15:59
@NiklasBerglund this should be addressed, there's nothing intrinsically RESTful about this, you simply
have better access to request methods this way. X is request and any HTTP 1.1 method can be
used with it (according to the docs), ie. get,post,put,delete,head,options,trace,connect and
presumably patch - FWIW, RESTful implies the url represents the state being accessed, and the method
(adequately) describes the operation being performed. Slomojo Aug 17 '13 at 14:55
curld"name=Rafael%20Sagula&phone=3320780"http://www.where.com/guest.cgi
Community
Daok
989
13
19
Output:
<p>Hello<strong>world</strong>!</p>
12
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.
2 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
curlvdataasciivar=valuehttp://example.com
and there are many more options, check curlhelp for more information.
edited Nov 5 '11 at 1:36
Tom Wijsman
43.4k
17
130
Vinko Vrsalovic
209
1,766
14
18