Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I execute an HTTP PUT in bash?

Tags:

put

bash

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?

like image 549
John Avatar asked Dec 11 '11 20:12

John


2 Answers

With curl it would be something like

curl --request PUT --header "Content-Length: 0" http://website.com/project?id=1

but like Mattias said you'd probably want some data in the body as well so you'd want the content-type and the data as well (plus content-length would be larger)

like image 111
Arnon Rotem-Gal-Oz Avatar answered Oct 06 '22 17:10

Arnon Rotem-Gal-Oz


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?

like image 29
Mattias Wadman Avatar answered Oct 06 '22 18:10

Mattias Wadman