代码拉取完成,页面将自动刷新
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.ResponseCompression;
using Microsoft.Extensions.DependencyInjection;
using System.IO.Compression;
using System;
using System.Linq;
using System.Net;
using System.Threading.Tasks;
namespace testdot
{
class Program
{
static IWebHost host;
static void Main(string[] args)
{
int port = 1988;
host = new WebHostBuilder().UseKestrel((options) =>
{
options.Listen(IPAddress.Any, port, listenOptions => { });
}).Configure(app =>
{
app.Run(ProcessAsync);
}).Build();
Console.WriteLine("http begin at:1988");
host.Start();
//mainthread loop
while (true)
{
Console.ReadLine();
}
}
static async Task ProcessAsync(HttpContext context)
{
try
{
context.Response.ContentType = "application/json;charset=UTF-8";
context.Response.Headers["Access-Control-Allow-Origin"] = "*";
context.Response.Headers["Access-Control-Allow-Methods"] = "GET, POST";
context.Response.Headers["Access-Control-Allow-Headers"] = "Content-Type";
context.Response.Headers["Access-Control-Max-Age"] = "31536000";
var path = context.Request.Path.Value;
await context.Response.WriteAsync("hello:"+path);
}
catch
{
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。