From 6a175f1592563cc7cd3691dc1f02ba062991eb74 Mon Sep 17 00:00:00 2001 From: DaichiSaito Date: Wed, 21 Apr 2021 23:03:35 +0900 Subject: [PATCH] add form --- form.html | 35 +++++++++++++++++++++++++++++++++++ webrick.rb | 24 ++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 form.html diff --git a/form.html b/form.html new file mode 100644 index 0000000..8ff5dcf --- /dev/null +++ b/form.html @@ -0,0 +1,35 @@ + + + + + + + +
+ GETで送る +
+ + +
+
+ + +
+ +
+ +
+ POSTで送る +
+ + +
+
+ + +
+ +
+ + + \ No newline at end of file diff --git a/webrick.rb b/webrick.rb index ab2c3cf..42962f0 100644 --- a/webrick.rb +++ b/webrick.rb @@ -17,4 +17,28 @@ res.body = body end +server.mount_proc("/form_get") do |req, res| + # レスポンス内容を出力 + body = "\n" + body += "クエリパラメータは#{req.query}です
\n" + body += "こんにちは#{req.query['username']}さん。" + body += "あなたの年齢は#{req.query['age']}ですね" + body += "\n" + res.status = 200 + res['Content-Type'] = 'text/html' + res.body = body +end + +server.mount_proc("/form_post") do |req, res| + # レスポンス内容を出力 + body = "\n" + body += "フォームデータは#{req.query}です
\n" + body += "こんにちは#{req.query['username']}さん。" + body += "あなたの年齢は#{req.query['age']}ですね" + body += "\n" + res.status = 200 + res['Content-Type'] = 'text/html' + res.body = body +end + server.start