56

I am trying to use Wget to access a RESTful interface, but I can not figure out how to do HTTP PUT with Wget. How can I do it? Or isn't it prossible?

5 Answers 5

95
wget --method=PUT --body-data=<STRING>

This is a bit late, but at some point after the original post, they added a "--method" option. I'm not sure when it was added, but see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=684189#24 for details.

7
  • 7
    This should be accepted answer.
    – Vanuan
    Commented Oct 14, 2016 at 2:17
  • 4
    Should be accepted answer in 2014, 2016 or whenever. --method param wasn't avail in wget back in 2010 :( Commented Nov 9, 2016 at 13:09
  • 16
    Not in busy box Commented Jul 10, 2017 at 21:04
  • 3
    --method still not available in centos 7.
    – David V.
    Commented Jul 9, 2019 at 11:15
  • 6
    Note only with GNU wget, not busybox wget.
    – Ben
    Commented Apr 3, 2020 at 19:27
26

Wget can't do PUT. Use cURL instead, with -T.

2
  • there's also a wput utility tho it seems limited to FTP. Commented Apr 12, 2010 at 8:19
  • 16
    Wget can now do PUT using --method.
    – John Henry
    Commented Oct 19, 2014 at 17:42
23

Since this is REST interface, I think you'd want to use curl with -X PUT, like this:

curl -i -X PUT http://www.example.tld/rest/updateEntity/1234?active=false

Or if you need to "post" data from a file, like an XML:

curl -i -X PUT -H "Content-Type: application/xml; charset=utf-8" -d @"/tmp/some-file.xml" http://www.example.tld/rest/updateEntity
6

For me following worked:

curl -T <file-path> <url>

For some reason when I did following it nothing happened (no error as well):

curl -X PUT -d <file-path> <url>         (did not work)
1
  • 2
    -d will send the data you entered on the command line, so it will try to PUT file path as text.
    – che
    Commented Jan 8, 2013 at 16:51
4

If you don't want to use a file as data, you can do the following.

curl -X PUT -d "something=blabla&somethingelse=blaha" http://www.example.com
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .