How can I do a HTTP PUT with Wget?

38

4

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?

Jonas

Posted 2010-04-12T08:02:18.210

Reputation: 21 007

Answers

23

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

Ignacio Vazquez-Abrams

Posted 2010-04-12T08:02:18.210

Reputation: 100 516

11Wget can now do PUT using --method. – John Henry – 2014-10-19T17:42:42.977

there's also a wput utility tho it seems limited to FTP.

– quack quixote – 2010-04-12T08:19:37.760

55

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.

John Henry

Posted 2010-04-12T08:02:18.210

Reputation: 651

5This should be accepted answer. – Vanuan – 2016-10-14T02:17:37.023

3Should be accepted answer in 2014, 2016 or whenever. --method param wasn't avail in wget back in 2010 :( – Bernhard Döbler – 2016-11-09T13:09:06.283

5Not in busy box – Dmitry Minkovsky – 2017-07-10T21:04:45.100

Seems not working when using with authentication. I tried wget --method=PUT with digest access authentication but wget don't performs the authentication procedure like it do with standard GET request. – Joe – 2017-09-22T00:01:57.707

2--method still not available in centos 7. – David V. – 2019-07-09T11:15:29.090

21

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

Sverre Marvik

Posted 2010-04-12T08:02:18.210

Reputation: 361

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)

hznut

Posted 2010-04-12T08:02:18.210

Reputation: 61

1-d will send the data you entered on the command line, so it will try to PUT file path as text. – che – 2013-01-08T16:51:39.280

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

fredrik

Posted 2010-04-12T08:02:18.210

Reputation: 141