Arin Arin - 21 days ago 4x
HTTP Question

Terminal - How to run the HTTP request 'PUT'

So, what I am trying to do is run from Terminal in Linux an HTTP request, 'PUT'. Not POST, not GET, 'PUT'.

I know in terminal you can just type 'GET', but when I did 'PUT' (And a bunch of other variables after that...), Terminal said that PUT is not a command.

Here's what I tried:

:~$ PUT
PUT: command not found

Well, is there a substitute for the command 'PUT', or some way of sending that HTTP request from terminal?

I don't want to use any external programs.... I don't want to download or install anything. Any other ways?


You are getting

Terminal said that PUT is not a command.

because the information is not being redirected via a network connection (to something that understands HTTP). bash has limited support by itself for communicating over a network, as discussed in

Besides that, the HTTP specification says of PUT:

The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI.

Clarifying, if you are PUTing to an existing URI, you may be able to do this, and the command implictly needs some data to reflect a modification.

The example in HTTP - Methods (TutorialsPoint) shows a PUT command used to store an HTML body on a URI. Your script has to redirect the data (as well as the initial request) onto the network connection.

You could do all of that using a here-document, or redirecting a file, e.g., (using that example to show how it might be adapted):

cat >/dev/tcp/ <<EOF
PUT /hello.htm HTTP/1.1
User-Agent: Mozilla/4.0 (compatible; MSIE5.01; Windows NT)
Accept-Language: en-us
Connection: Keep-Alive
Content-type: text/html
Content-Length: 182
<h1>Hello, World!</h1>

But your script should also provide for reading the server's response.