DotnetCGI
1.0.0
该代码说明了如何使用C#实现通用网关接口标准。我创建了一个简单的CGIContext类,该类将从Web服务器传递的环境变量中构建HTTPRequestMessage。然后,您可以使用它来读取输入并做出适当的响应。
为什么?为什么不呢?这主要是教育性的,可以看到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();