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();