win2kp.HttpListenerImpl 1.0.0

易于使用的HttpListener封装库,事件方式实现对客户端的请求处理。支持SSL,摘要式身份验证,客户端会话,简化的JSON POST处理方式,建议用于嵌入服务类程序作为接口使用

There is a newer version of this package available.
See the version list below for details.
Install-Package win2kp.HttpListenerImpl -Version 1.0.0
dotnet add package win2kp.HttpListenerImpl --version 1.0.0
<PackageReference Include="win2kp.HttpListenerImpl" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add win2kp.HttpListenerImpl --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

<code>
using System;
using System.Net;
using HttpAppController;

namespace ConsoleApp1
{
class Program
{
private static string _appId = Guid.NewGuid().ToString();
static void Main(string[] args)
{
HttpAppController.HttpAppController controller = new HttpAppController.HttpAppController
(
new System.Collections.Generic.Dictionary<string, string>(), // macros (%key) will be replaced with value in static html/text file
8080, // port to listen
"/api", // prefix
_appId, // appid for SSL enabled site
"cert.pfx", // certificate used with SSL
"password_to_export_cert", // password to export pfx cert
true, // allow client to access static file in program folder (like html, txt, etc.)
"." // Realm to used with authentication
);

        controller.AuthenLocal = true;  // Authenticate user from localhost?
        controller.NeedAuthentication = true; // Enable digest authentication on the site;
        controller.SessionTimeout = 30000; // timeout for user session (ms)
        controller.Request += Controller_Request;
        controller.ClientAuthentication += Controller_ClientAuthentication;
        controller.Start();

    }

    private static void Controller_ClientAuthentication(string username, ref string password, ref bool userExists)
    {
        userExists = true;      //tell the username is valid
        password = "password";  // tell the password for the username 
    }

    private static void Controller_Request(Guid guid, HttpListenerRequest request, string cmd, System.Collections.Generic.Dictionary<string, string> param, dynamic json, ref string response)
    {
        // cmd: will be the "Command" part in url http://xxxxxx:8080/prefix/Command
        // param: the querystrings within the request
        // json: JSON entity posted from client (if applicable)
        // response: the content will be sent to client
        if (cmd == "Hello")
        {
            response = "Hello, " + param["name"];
            // response = "Hello, " + json.name;
        }


    }
}

}
</code>

<code>
using System;
using System.Net;
using HttpAppController;

namespace ConsoleApp1
{
class Program
{
private static string _appId = Guid.NewGuid().ToString();
static void Main(string[] args)
{
HttpAppController.HttpAppController controller = new HttpAppController.HttpAppController
(
new System.Collections.Generic.Dictionary<string, string>(), // macros (%key) will be replaced with value in static html/text file
8080, // port to listen
"/api", // prefix
_appId, // appid for SSL enabled site
"cert.pfx", // certificate used with SSL
"password_to_export_cert", // password to export pfx cert
true, // allow client to access static file in program folder (like html, txt, etc.)
"." // Realm to used with authentication
);

        controller.AuthenLocal = true;  // Authenticate user from localhost?
        controller.NeedAuthentication = true; // Enable digest authentication on the site;
        controller.SessionTimeout = 30000; // timeout for user session (ms)
        controller.Request += Controller_Request;
        controller.ClientAuthentication += Controller_ClientAuthentication;
        controller.Start();

    }

    private static void Controller_ClientAuthentication(string username, ref string password, ref bool userExists)
    {
        userExists = true;      //tell the username is valid
        password = "password";  // tell the password for the username 
    }

    private static void Controller_Request(Guid guid, HttpListenerRequest request, string cmd, System.Collections.Generic.Dictionary<string, string> param, dynamic json, ref string response)
    {
        // cmd: will be the "Command" part in url http://xxxxxx:8080/prefix/Command
        // param: the querystrings within the request
        // json: JSON entity posted from client (if applicable)
        // response: the content will be sent to client
        if (cmd == "Hello")
        {
            response = "Hello, " + param["name"];
            // response = "Hello, " + json.name;
        }


    }
}

}
</code>

Release Notes

First upload

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.1 75 7/1/2019
1.0.0 66 6/27/2019