DotnetCGI
1.0.0
このコードは、C#を使用してCommon Gatewayインターフェイス標準を実装する方法を示しています。 Webサーバーで渡された環境変数からHTTPRequestMessageを構築するシンプルなCGICONTEXTクラスを作成しました。その後、それを使用して入力を読み取り、適切に応答できます。
なぜ?なぜだめですか?これは、CGIがIPCメソッドとしてどのように機能するかを確認するための単なる教育でした。
サンプル
using Dotnet.Cgi;
using Newtonsoft.Json.Linq;
var app = new CgiApp();
app.Map(HttpMethod.Get, "/cgi/SampleCgiApp.exe/", async (context, parameters) =>
{
var responseContent = new JObject
{
["env"] = JObject.FromObject(Environment.GetEnvironmentVariables()),
["context"] = JObject.FromObject(context),
["requestBody"] = context.Request.Content?.ReadAsStringAsync().Result,
};
await context.Created(responseContent);
});
await app.Execute();