How can I send different HTTP request methods over my browser? I am using chrome, but any other would do.
For example, I would like to try out TRACE
or OPTIONS
methods for educational purposes. Any idea how I can do that?
Example:
request message:
OPTIONS * HTTP/1.1
Host: www.joes-hardware.com
Accept: *
response message:
HTTP/1.1 200 OK
Allow: GET, POST, PUT, OPTIONS
Context-length: 0
Browsers themselves do not issue any requests with verbs (read: methods) other than GET
, POST
, and HEAD
. By the powers of ajax though, they can be made to use a wealth of other methods through the XmlHttpRequest object. However, you will be out of luck with the TRACE
verb:
If method is a case-sensitive match for
CONNECT
,TRACE
, orTRACK
, throw a "SecurityError" exception and terminate these steps.
If you do not want or do not need to be bound to a browser, there are quite a few options. For starters, Perl's libwww library comes with the GET
, HEAD
, and POST
commandline utilities that are quite neat to use.
A more complete solution is cURL, which is a pretty complete solution for a multitude of protocols. Its original purpose has been to simply catch a file from an URL (catch URL = cURL) which does not necessarily mean from an HTTP server. With a well-formed URL, cURL can download an attachment from an e-mail on an IMAP server. You will be most interested into the -X
option of cURL's commandline interface, which allows you to specify arbitrary verbs for an HTTP request. But as mighty as it may be, there will probably be no way to issue that OPTIONS * HTTP/1.1
request with it.
As a last-ditch effort, I can wholeheartedly recommend netcat, which accepts piped input and is fully able to handle encryption (which is way more comfortable than openssl's s_client). You may already know that you can emulate HTTP requests over telnet (if you type fast enough). But I believe you will find netcat with some heredoc way more comfortable:
$ nc -v localhost 80 <<EOD
GET / HTTP/1.1
Host: localhost
Connection: close
EOD
netcat speaks no HTTP itself, so you alone are responsible for the syntactical correctness of your requests. On the other hand, this allows you total freedom to experiment around.