#
ドキュメント

Document

自分のための備忘録です。

ncコマンドを使ったHTTP通信

HTTPサーバ稼働

$ pwd
// /home/ubuntu
$ mkdir web
$ cd web
$ python3 -m SimpleHTTPServer
Serving HTTP on 127.0.0.1 port 80 (http://127.0.0.1:80/) ...

リクエスト

ncコマンドを使用する例。

$ pwd
// /home/ubuntu
$ echo -en "GET / HTTP/1.0\r\n\r\n" | nc 127.0.0.1 80
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.8.10
Date: Sat, 09 Apr 2022 01:11:59 GMT
Content-type: text/html
Content-Length: 103
Last-Modified: Sat, 09 Apr 2022 01:09:40 GMT

<html>
  <head>
    <title>Welcom to web1</title>
  </head>
  <body>
    Hello World
  </body>
</html>
ubuntu@ip-10-3-0-183:~$ echo -en "GET / HTTP/1.0\r\n\r\n" | nc 127.0.0.1 80
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.8.10
Date: Sat, 09 Apr 2022 01:12:10 GMT
Content-type: text/html
Content-Length: 103
Last-Modified: Sat, 09 Apr 2022 01:09:40 GMT

<html>
  <head>
    <title>Welcom to web1</title>
  </head>
  <body>
    Hello World
  </body>
</html>

curlコマンドを使用する例

$ curl -X GET -D - http://127.0.0.1/
HTTP/1.0 200 OK
Server: SimpleHTTP/0.6 Python/3.8.10
Date: Sat, 09 Apr 2022 01:18:33 GMT
Content-type: text/html
Content-Length: 103
Last-Modified: Sat, 09 Apr 2022 01:09:40 GMT

<html>
  <head>
    <title>Welcom to web1</title>
  </head>
  <body>
    Hello World
  </body>
</html>