How do I execute an HTTP PUT in bash?

John picture John · Dec 11, 2011 · Viewed 11.5k times · Source

I'm sending requests to a third-party API. It says I must send an HTTP PUT to http://example.com/project?id=projectId

I tried doing this with PHP curl, but I'm not getting a response from the server. Maybe something is wrong with my code because I've never used PUT before. Is there a way for me to execute an HTTP PUT from bash command line? If so, what is the command?

Answer

Mattias Wadman picture Mattias Wadman · Dec 11, 2011

If you really want to only use bash it actually has some networking support.

 echo -e "PUT /project?id=123 HTTP/1.1\r\nHost: website.com\r\n\r\n" > \
   /dev/tcp/website.com/80

But I guess you also want to send some data in the body?