.netの HttpListener を使ったサーバ構築が面白そうなのでチャレンジ中だが、どういったデータ構造なのか、どんな値が入っているのか、ドキュメントだけだとなかなか創造できない。
そのため、 HttpListenerを使ったローカルWebサーバ のサンプルプログラムから、構成する各種オブジェクトのプロパティを 一括で確認するためのサンプルコードを作成した。
サンプルコード
使い方
- サンプルコードをPowerShellに張り付けて実行する。
- ブラウザからhttp://localhost:8000/ にアクセス
- PowerShellのコンソール上に以下の実行結果が出力される。
実行結果
Windows10 Edgeから実行した場合
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
PS C:\Users\papanda925\Desktop\httpsv> c:\Users\papanda925\Desktop\httpsv\sampleSV.ps1 ---- $listener Start ---- ---- $listener Property Count: 11 ---- 1 $listener.AuthenticationSchemes : Anonymous 2 $listener.AuthenticationSchemeSelectorDelegate : 3 $listener.DefaultServiceNames : HTTP/localhost HTTP/DESKTOP-AJDBM1N 4 $listener.ExtendedProtectionPolicy : ProtectionScenario=TransportSelected; PolicyEnforcement=Never; CustomChannelBinding=<null>; ServiceNames=<null> 5 $listener.ExtendedProtectionSelectorDelegate : 6 $listener.IgnoreWriteExceptions : False 7 $listener.IsListening : True 8 $listener.Prefixes : http://localhost:8000/ 9 $listener.Realm : 10 $listener.TimeoutManager : System.Net.HttpListenerTimeoutManager 11 $listener.UnsafeConnectionNtlmAuthentication : False ---- $listener.TimeoutManager Start ---- ---- $listener.TimeoutManager Property Count: 6 ---- 1 $listener.TimeoutManager.DrainEntityBody : 00:00:00 2 $listener.TimeoutManager.EntityBody : 00:00:00 3 $listener.TimeoutManager.HeaderWait : 00:00:00 4 $listener.TimeoutManager.IdleConnection : 00:00:00 5 $listener.TimeoutManager.MinSendBytesPerSecond : 0 6 $listener.TimeoutManager.RequestQueue : 00:00:00 ---- $context Start ---- ---- $context Property Count: 3 ---- 1 $context.Request : System.Net.HttpListenerRequest 2 $context.Response : System.Net.HttpListenerResponse 3 $context.User : ---- $context.Request Start ---- ---- $context.Request Property Count: 29 ---- 1 $context.Request.AcceptTypes : text/html application/xhtml+xml application/xml;q=0.9 image/webp image/apng */*;q=0.8 application/signed-exchange;v=b3;q=0.9 2 $context.Request.ClientCertificateError : 3 $context.Request.ContentEncoding : System.Text.DBCSCodePageEncoding 4 $context.Request.ContentLength64 : 0 5 $context.Request.ContentType : 6 $context.Request.Cookies : 7 $context.Request.HasEntityBody : False 8 $context.Request.Headers : sec-ch-ua sec-ch-ua-mobile sec-ch-ua-platform Upgrade-Insecure-Requests Sec-Fetch-Site Sec-Fetch-Mode Sec-Fetch-User Sec-Fetch-Dest Cache-Control Connection Accept Accept-Encoding Accept-Language Host User-Agent 9 $context.Request.HttpMethod : GET 10 $context.Request.InputStream : System.IO.Stream+NullStream 11 $context.Request.IsAuthenticated : False 12 $context.Request.IsLocal : True 13 $context.Request.IsSecureConnection : False 14 $context.Request.IsWebSocketRequest : False 15 $context.Request.KeepAlive : True 16 $context.Request.LocalEndPoint : [::1]:8000 17 $context.Request.ProtocolVersion : 1.1 18 $context.Request.QueryString : 19 $context.Request.RawUrl : / 20 $context.Request.RemoteEndPoint : [::1]:53699 21 $context.Request.RequestTraceIdentifier : 00000000-0000-0000-1700-0080010000fb 22 $context.Request.ServiceName : 23 $context.Request.TransportContext : System.Net.HttpListenerRequestContext 24 $context.Request.Url : http://localhost:8000/ 25 $context.Request.UrlReferrer : 26 $context.Request.UserAgent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.47 27 $context.Request.UserHostAddress : [::1]:8000 28 $context.Request.UserHostName : localhost:8000 29 $context.Request.UserLanguages : ja en;q=0.9 en-GB;q=0.8 en-US;q=0.7 ---- $context.Request.Url Start ---- ---- $context.Request.Url Property Count: 22 ---- 1 $context.Request.Url.AbsolutePath : / 2 $context.Request.Url.AbsoluteUri : http://localhost:8000/ 3 $context.Request.Url.Authority : localhost:8000 4 $context.Request.Url.DnsSafeHost : localhost 5 $context.Request.Url.Fragment : 6 $context.Request.Url.Host : localhost 7 $context.Request.Url.HostNameType : Dns 8 $context.Request.Url.IdnHost : localhost 9 $context.Request.Url.IsAbsoluteUri : True 10 $context.Request.Url.IsDefaultPort : False 11 $context.Request.Url.IsFile : False 12 $context.Request.Url.IsLoopback : True 13 $context.Request.Url.IsUnc : False 14 $context.Request.Url.LocalPath : / 15 $context.Request.Url.OriginalString : http://localhost:8000/ 16 $context.Request.Url.PathAndQuery : / 17 $context.Request.Url.Port : 8000 18 $context.Request.Url.Query : 19 $context.Request.Url.Scheme : http 20 $context.Request.Url.Segments : / 21 $context.Request.Url.UserEscaped : False 22 $context.Request.Url.UserInfo : ---- $context.Request.Headers Start ---- ---- $context.Request.Headers Property Count: 1 ---- 1 $context.Request.Headers.Length : 9 16 18 25 14 14 14 14 13 10 6 15 15 4 10 ---- $context.Request.InputStream Start ---- ---- $context.Request.InputStream Property Count: 8 ---- 1 $context.Request.InputStream.CanRead : True 2 $context.Request.InputStream.CanSeek : True 3 $context.Request.InputStream.CanTimeout : False 4 $context.Request.InputStream.CanWrite : True 5 $context.Request.InputStream.Length : 0 6 $context.Request.InputStream.Position : 0 7 $context.Request.InputStream.ReadTimeout : 8 $context.Request.InputStream.WriteTimeout : ---- $context.Request.TransportContext Start ---- ---- $context.Request.TransportContext Property Count: 0 ---- ---- $context.Request.UrlReferrer Is Null ---- ---- $context.Request.RequestTraceIdentifier Start ---- ---- $context.Request.RequestTraceIdentifier Property Count: 0 ---- ---- $context.Request.ContentEncoding Start ---- ---- $context.Request.ContentEncoding Property Count: 14 ---- 1 $context.Request.ContentEncoding.BodyName : iso-2022-jp 2 $context.Request.ContentEncoding.CodePage : 932 3 $context.Request.ContentEncoding.DecoderFallback : System.Text.InternalDecoderBestFitFallback 4 $context.Request.ContentEncoding.EncoderFallback : System.Text.InternalEncoderBestFitFallback 5 $context.Request.ContentEncoding.EncodingName : 日本語 (シフト JIS) 6 $context.Request.ContentEncoding.HeaderName : iso-2022-jp 7 $context.Request.ContentEncoding.IsBrowserDisplay : True 8 $context.Request.ContentEncoding.IsBrowserSave : True 9 $context.Request.ContentEncoding.IsMailNewsDisplay : True 10 $context.Request.ContentEncoding.IsMailNewsSave : True 11 $context.Request.ContentEncoding.IsReadOnly : True 12 $context.Request.ContentEncoding.IsSingleByte : False 13 $context.Request.ContentEncoding.WebName : shift_jis 14 $context.Request.ContentEncoding.WindowsCodePage : 932 ---- $context.User Is Null ---- ---- $context.Response Start ---- ---- $context.Response Property Count: 12 ---- 1 $context.Response.ContentEncoding : 2 $context.Response.ContentLength64 : 0 3 $context.Response.ContentType : 4 $context.Response.Cookies : 5 $context.Response.Headers : 6 $context.Response.KeepAlive : True 7 $context.Response.OutputStream : System.Net.HttpResponseStream 8 $context.Response.ProtocolVersion : 1.1 9 $context.Response.RedirectLocation : 10 $context.Response.SendChunked : False 11 $context.Response.StatusCode : 200 12 $context.Response.StatusDescription : OK ---- $context.Response.OutputStream Start ---- ---- $context.Response.OutputStream Property Count: 8 ---- 1 $context.Response.OutputStream.CanRead : False 2 $context.Response.OutputStream.CanSeek : False 3 $context.Response.OutputStream.CanTimeout : False 4 $context.Response.OutputStream.CanWrite : True 5 $context.Response.OutputStream.Length : 6 $context.Response.OutputStream.Position : 7 $context.Response.OutputStream.ReadTimeout : 8 $context.Response.OutputStream.WriteTimeout : ---- $listener Start ---- ---- $listener Property Count: 11 ---- 1 $listener.AuthenticationSchemes : Anonymous 2 $listener.AuthenticationSchemeSelectorDelegate : 3 $listener.DefaultServiceNames : HTTP/localhost HTTP/DESKTOP-AJDBM1N 4 $listener.ExtendedProtectionPolicy : ProtectionScenario=TransportSelected; PolicyEnforcement=Never; CustomChannelBinding=<null>; ServiceNames=<null> 5 $listener.ExtendedProtectionSelectorDelegate : 6 $listener.IgnoreWriteExceptions : False 7 $listener.IsListening : True 8 $listener.Prefixes : http://localhost:8000/ 9 $listener.Realm : 10 $listener.TimeoutManager : System.Net.HttpListenerTimeoutManager 11 $listener.UnsafeConnectionNtlmAuthentication : False ---- $listener.TimeoutManager Start ---- ---- $listener.TimeoutManager Property Count: 6 ---- 1 $listener.TimeoutManager.DrainEntityBody : 00:00:00 2 $listener.TimeoutManager.EntityBody : 00:00:00 3 $listener.TimeoutManager.HeaderWait : 00:00:00 4 $listener.TimeoutManager.IdleConnection : 00:00:00 5 $listener.TimeoutManager.MinSendBytesPerSecond : 0 6 $listener.TimeoutManager.RequestQueue : 00:00:00 ---- $context Start ---- ---- $context Property Count: 3 ---- 1 $context.Request : System.Net.HttpListenerRequest 2 $context.Response : System.Net.HttpListenerResponse 3 $context.User : ---- $context.Request Start ---- ---- $context.Request Property Count: 29 ---- 1 $context.Request.AcceptTypes : image/webp image/apng image/svg+xml image/* */*;q=0.8 2 $context.Request.ClientCertificateError : 3 $context.Request.ContentEncoding : System.Text.DBCSCodePageEncoding 4 $context.Request.ContentLength64 : 0 5 $context.Request.ContentType : 6 $context.Request.Cookies : 7 $context.Request.HasEntityBody : False 8 $context.Request.Headers : sec-ch-ua sec-ch-ua-mobile sec-ch-ua-platform Sec-Fetch-Site Sec-Fetch-Mode Sec-Fetch-Dest Cache-Control Connection Pragma Accept Accept-Encoding Accept-Language Host Referer User-Agent 9 $context.Request.HttpMethod : GET 10 $context.Request.InputStream : System.IO.Stream+NullStream 11 $context.Request.IsAuthenticated : False 12 $context.Request.IsLocal : True 13 $context.Request.IsSecureConnection : False 14 $context.Request.IsWebSocketRequest : False 15 $context.Request.KeepAlive : True 16 $context.Request.LocalEndPoint : [::1]:8000 17 $context.Request.ProtocolVersion : 1.1 18 $context.Request.QueryString : 19 $context.Request.RawUrl : /favicon.ico 20 $context.Request.RemoteEndPoint : [::1]:53699 21 $context.Request.RequestTraceIdentifier : 00000000-0000-0000-1800-0080010000fb 22 $context.Request.ServiceName : 23 $context.Request.TransportContext : System.Net.HttpListenerRequestContext 24 $context.Request.Url : http://localhost:8000/favicon.ico 25 $context.Request.UrlReferrer : http://localhost:8000/ 26 $context.Request.UserAgent : Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.47 27 $context.Request.UserHostAddress : [::1]:8000 28 $context.Request.UserHostName : localhost:8000 29 $context.Request.UserLanguages : ja en;q=0.9 en-GB;q=0.8 en-US;q=0.7 ---- $context.Request.Url Start ---- ---- $context.Request.Url Property Count: 22 ---- 1 $context.Request.Url.AbsolutePath : /favicon.ico 2 $context.Request.Url.AbsoluteUri : http://localhost:8000/favicon.ico 3 $context.Request.Url.Authority : localhost:8000 4 $context.Request.Url.DnsSafeHost : localhost 5 $context.Request.Url.Fragment : 6 $context.Request.Url.Host : localhost 7 $context.Request.Url.HostNameType : Dns 8 $context.Request.Url.IdnHost : localhost 9 $context.Request.Url.IsAbsoluteUri : True 10 $context.Request.Url.IsDefaultPort : False 11 $context.Request.Url.IsFile : False 12 $context.Request.Url.IsLoopback : True 13 $context.Request.Url.IsUnc : False 14 $context.Request.Url.LocalPath : /favicon.ico 15 $context.Request.Url.OriginalString : http://localhost:8000/favicon.ico 16 $context.Request.Url.PathAndQuery : /favicon.ico 17 $context.Request.Url.Port : 8000 18 $context.Request.Url.Query : 19 $context.Request.Url.Scheme : http 20 $context.Request.Url.Segments : / favicon.ico 21 $context.Request.Url.UserEscaped : False 22 $context.Request.Url.UserInfo : ---- $context.Request.Headers Start ---- ---- $context.Request.Headers Property Count: 1 ---- 1 $context.Request.Headers.Length : 9 16 18 14 14 14 13 10 6 6 15 15 4 7 10 ---- $context.Request.InputStream Start ---- ---- $context.Request.InputStream Property Count: 8 ---- 1 $context.Request.InputStream.CanRead : True 2 $context.Request.InputStream.CanSeek : True 3 $context.Request.InputStream.CanTimeout : False 4 $context.Request.InputStream.CanWrite : True 5 $context.Request.InputStream.Length : 0 6 $context.Request.InputStream.Position : 0 7 $context.Request.InputStream.ReadTimeout : 8 $context.Request.InputStream.WriteTimeout : ---- $context.Request.TransportContext Start ---- ---- $context.Request.TransportContext Property Count: 0 ---- ---- $context.Request.UrlReferrer Start ---- ---- $context.Request.UrlReferrer Property Count: 22 ---- 1 $context.Request.UrlReferrer.AbsolutePath : / 2 $context.Request.UrlReferrer.AbsoluteUri : http://localhost:8000/ 3 $context.Request.UrlReferrer.Authority : localhost:8000 4 $context.Request.UrlReferrer.DnsSafeHost : localhost 5 $context.Request.UrlReferrer.Fragment : 6 $context.Request.UrlReferrer.Host : localhost 7 $context.Request.UrlReferrer.HostNameType : Dns 8 $context.Request.UrlReferrer.IdnHost : localhost 9 $context.Request.UrlReferrer.IsAbsoluteUri : True 10 $context.Request.UrlReferrer.IsDefaultPort : False 11 $context.Request.UrlReferrer.IsFile : False 12 $context.Request.UrlReferrer.IsLoopback : True 13 $context.Request.UrlReferrer.IsUnc : False 14 $context.Request.UrlReferrer.LocalPath : / 15 $context.Request.UrlReferrer.OriginalString : http://localhost:8000/ 16 $context.Request.UrlReferrer.PathAndQuery : / 17 $context.Request.UrlReferrer.Port : 8000 18 $context.Request.UrlReferrer.Query : 19 $context.Request.UrlReferrer.Scheme : http 20 $context.Request.UrlReferrer.Segments : / 21 $context.Request.UrlReferrer.UserEscaped : False 22 $context.Request.UrlReferrer.UserInfo : ---- $context.Request.RequestTraceIdentifier Start ---- ---- $context.Request.RequestTraceIdentifier Property Count: 0 ---- ---- $context.Request.ContentEncoding Start ---- ---- $context.Request.ContentEncoding Property Count: 14 ---- 1 $context.Request.ContentEncoding.BodyName : iso-2022-jp 2 $context.Request.ContentEncoding.CodePage : 932 3 $context.Request.ContentEncoding.DecoderFallback : System.Text.InternalDecoderBestFitFallback 4 $context.Request.ContentEncoding.EncoderFallback : System.Text.InternalEncoderBestFitFallback 5 $context.Request.ContentEncoding.EncodingName : 日本語 (シフト JIS) 6 $context.Request.ContentEncoding.HeaderName : iso-2022-jp 7 $context.Request.ContentEncoding.IsBrowserDisplay : True 8 $context.Request.ContentEncoding.IsBrowserSave : True 9 $context.Request.ContentEncoding.IsMailNewsDisplay : True 10 $context.Request.ContentEncoding.IsMailNewsSave : True 11 $context.Request.ContentEncoding.IsReadOnly : True 12 $context.Request.ContentEncoding.IsSingleByte : False 13 $context.Request.ContentEncoding.WebName : shift_jis 14 $context.Request.ContentEncoding.WindowsCodePage : 932 ---- $context.User Is Null ---- ---- $context.Response Start ---- ---- $context.Response Property Count: 12 ---- 1 $context.Response.ContentEncoding : 2 $context.Response.ContentLength64 : 0 3 $context.Response.ContentType : 4 $context.Response.Cookies : 5 $context.Response.Headers : 6 $context.Response.KeepAlive : True 7 $context.Response.OutputStream : System.Net.HttpResponseStream 8 $context.Response.ProtocolVersion : 1.1 9 $context.Response.RedirectLocation : 10 $context.Response.SendChunked : False 11 $context.Response.StatusCode : 200 12 $context.Response.StatusDescription : OK ---- $context.Response.OutputStream Start ---- ---- $context.Response.OutputStream Property Count: 8 ---- 1 $context.Response.OutputStream.CanRead : False 2 $context.Response.OutputStream.CanSeek : False 3 $context.Response.OutputStream.CanTimeout : False 4 $context.Response.OutputStream.CanWrite : True 5 $context.Response.OutputStream.Length : 6 $context.Response.OutputStream.Position : 7 $context.Response.OutputStream.ReadTimeout : 8 $context.Response.OutputStream.WriteTimeout : |
なるほどいろいろとできそうな予感。パラメータがいろいろあって楽しそう。メソッドはどんな感じなんだろう。
コメント