curl: PUT

Testing curl PUT commands.

Start by creating an HTTP PUT server:

# python -m SimpleHTTPPutServer 8080
import SimpleHTTPServer
import BaseHTTPServer

class SputHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
    def do_PUT(self):
        print self.headers
        length = int(self.headers["Content-Length"])
        path = self.translate_path(self.path)
        with open(path, "wb") as dst:
            dst.write(self.rfile.read(length))


if __name__ == '__main__':
    SimpleHTTPServer.test(HandlerClass=SputHTTPRequestHandler)

and run with `python SimpleHTTPPutServer.py`

then:

curl -XPUT -H "Content-Type: application/json" http://localhost:8000 -d '{"test": null}'

and now you can mess around creating arbitrary PUT commands.

E.g.

  1. spaces don’t matter between -H and quotes.

-H"Content-Type

is the same as:

-H "Content-Type

2. Double quotes == Single quotes. E.g.

-H'Content is OK

3. argument to -dmust be surrounded in quotes. E.g.

-d 'test=test' is OK.

-d test=test is NOT OK.

E.g. see examples here:

https://gist.github.com/subfuzion/08c5d85437d5d4f00e58

 

Leave a Reply

Your email address will not be published. Required fields are marked *