I need to make a POST request via Curl from the command line. Data for this request is located in a file. I know that via PUT this could be done with the --upload-file option.

curl host:port/post-file -H "Content-Type: text/xml" --data "contents_of_file"
share|improve this question
    
    
Sorry maybe i mistakenly described my problem i need to send request not via php-curl but just via curl command from command line from linux os. – user253202 Jun 20 '11 at 9:13
1  
See also send/post xml file using curl command line. – Vadzim Oct 9 '13 at 7:59
up vote 153 down vote accepted

You're looking for the --data-binary argument:

curl -i -X POST host:port/post-file -H "Content-Type: text/xml" --data-binary "@path/to/file"

In the example above, -i prints out all the headers so that you can see what's going on, and -X POST makes it explicit that this is a post. Both of these can be safely omitted without changing the behaviour on the wire. The path to the file needs to be preceded by an @ symbol, so curl knows to read from a file.

share|improve this answer
    
what should be format of @path/to/file – ɢʜʘʂʈ ʀɛɔʘɴ Apr 25 '14 at 7:13
    
@ɢʜʘʂʈʀɛɔʘɴ in this case it would be .xml – dennismonsewicz Jun 4 '14 at 13:39
11  
the @ part is extremely important! – Ron Klein Aug 17 '14 at 15:13
    
So we use --data-binary parameter, but the actual file content can be text? Since XML isn't typically binary. – David Jul 13 '15 at 20:34
3  
actually you can use just -d flag – Tol182 Dec 9 '16 at 12:26

If you are using form data to upload file,in which a parameter name must be specified , you can use:

curl -X POST -i -F parametername=@filename host:port/xxx

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.