回答編集履歴
2
誤記修正
test
CHANGED
@@ -16,7 +16,9 @@
|
|
16
16
|
|
17
17
|
- いろいろ問題あり
|
18
18
|
|
19
|
+
- 実際には関数仕様を確認すること
|
20
|
+
|
19
|
-
|
21
|
+
> using System.IO;
|
20
22
|
|
21
23
|
> using System.Net;
|
22
24
|
|
1
実際に動作確認したソースコードに変更
test
CHANGED
@@ -6,40 +6,90 @@
|
|
6
6
|
|
7
7
|
|
8
8
|
|
9
|
+
- 最低限のコードだけ
|
10
|
+
|
11
|
+
- 動作確認済み
|
12
|
+
|
13
|
+
- エラー処理無し
|
14
|
+
|
15
|
+
- 自前で頑張るお勧めしないコード
|
16
|
+
|
17
|
+
- いろいろ問題あり
|
18
|
+
|
19
|
+
- 実際には関数仕様を確認すること> using System.IO;
|
20
|
+
|
21
|
+
> using System.Net;
|
22
|
+
|
23
|
+
>
|
24
|
+
|
25
|
+
> // http://127.0.0.1:8123 にアクセスしテキストを入力するとText.txtに内容が保存される
|
26
|
+
|
9
|
-
> s
|
27
|
+
> namespace WebLinkSample
|
10
28
|
|
11
29
|
> {
|
12
30
|
|
13
|
-
> s
|
31
|
+
> class Program
|
14
32
|
|
15
|
-
>
|
33
|
+
> {
|
16
34
|
|
17
|
-
>
|
35
|
+
> static void Main(string[] args)
|
18
36
|
|
37
|
+
> {
|
38
|
+
|
39
|
+
> HttpListener listener = new HttpListener();
|
40
|
+
|
41
|
+
> listener.Prefixes.Add("http://+:8123/");
|
42
|
+
|
19
|
-
> listener.Start();
|
43
|
+
> listener.Start();
|
44
|
+
|
45
|
+
> StreamWriter writer = new StreamWriter(@"Test.txt");
|
46
|
+
|
47
|
+
> while (true)
|
48
|
+
|
49
|
+
> {
|
50
|
+
|
51
|
+
> HttpListenerContext context = listener.GetContext();
|
52
|
+
|
53
|
+
> HttpListenerResponse res = context.Response;
|
20
54
|
|
21
55
|
>
|
22
56
|
|
23
|
-
> wh
|
57
|
+
> switch (context.Request.Url.AbsolutePath)
|
24
58
|
|
25
|
-
> {
|
59
|
+
> {
|
26
60
|
|
27
|
-
>
|
61
|
+
> case "/test.cgi":
|
28
62
|
|
29
|
-
>
|
63
|
+
> {
|
30
64
|
|
31
|
-
>
|
65
|
+
> StreamReader reader = new StreamReader(context.Request.InputStream);
|
32
66
|
|
33
|
-
> s
|
67
|
+
> string str = reader.ReadToEnd();
|
34
68
|
|
35
|
-
>
|
69
|
+
> writer.WriteLine(str);
|
36
70
|
|
37
|
-
> F
|
71
|
+
> writer.Flush();
|
38
72
|
|
73
|
+
> }
|
74
|
+
|
75
|
+
> break;
|
76
|
+
|
77
|
+
> }
|
78
|
+
|
79
|
+
> byte[] html = System.Text.Encoding.GetEncoding(932).GetBytes(@"<form action='test.cgi' method='post'><input type='text' name='name'></form>");
|
80
|
+
|
39
|
-
>
|
81
|
+
> context.Response.StatusCode = (int)HttpStatusCode.OK;
|
82
|
+
|
83
|
+
> context.Response.ContentType = "text/html";
|
84
|
+
|
85
|
+
> context.Response.OutputStream.Write(html, 0, html.Length);
|
86
|
+
|
87
|
+
> res.Close();
|
88
|
+
|
89
|
+
> }
|
90
|
+
|
91
|
+
> }
|
40
92
|
|
41
93
|
> }
|
42
94
|
|
43
|
-
> }
|
44
|
-
|
45
95
|
> }
|