在Visual Studio 中的NuGet管理器中可以下载安装,也可以直接在NuGet控制台输入下面的指令安装:
好了,我们开始一步步的说明。如何进行创建功能复杂的web api接口的。先简单的创建一个服务器对象
private HttpServer httpServer; // 当前的Web服务器,支持web api来通信的方式
private void Start( )
{
// 启动web的服务器
try
{
this.httpServer = new HttpServer( );
this.httpServer.Start( 8000 );
}
catch (Exception ex)
{
Console.WriteLine( "Web服务器加载失败!" + ex.Message );
}
}
// 调用start方法之后,我们打开浏览器,输入 http://127.0.0.1:8000 就可以看到如下的文本 "This is HslWebServer, Thank you for use!"
// After calling the start method, we open the browser and enter http://127.0.0.1:8000 to see the following text: "This is HslWebServer, Thank you for use!"
此时我们打开网页看看
通常来说,基本的实例化,返回固定的数据并不能满足我们的需求,我们需要返回自定义的数据,有一个委托,我们需要自己指定方法.
private HttpServer httpServer; // 当前的Web服务器,支持web api来通信的方式
private void Start( )
{
// 启动web的服务器
try
{
this.httpServer = new HttpServer( );
this.httpServer.HandleRequestFunc