Ai
1 Star 4 Fork 1

lights li/netcore_study

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
Program.cs 1.62 KB
一键复制 编辑 原始数据 按行查看 历史
lights li 提交于 2019-11-19 11:35 +08:00 . server01
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
{
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C#
1
https://gitee.com/lightsever/netcore_study.git
git@gitee.com:lightsever/netcore_study.git
lightsever
netcore_study
netcore_study
master

搜索帮助