• 大小: 248KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-14
  • 语言: C#
  • 标签: HTTPS  HTTP  SSL  Netsh  Listen  

资源简介

1、用C#的exe程序,搭建HTTPS监听,可用于静态网站、接口、模拟WebApi等等 2、由于是客户端EXE,可以正常访问客户端所有硬件资源 3、如:web界面上调用http://localhost:xx/+参数,调用本地硬件、本地缓存(内存或文件,可 代替cookies)、打开本地程序、调用打印机、扫码墩....

资源截图

代码片段和文件信息

using System;

public class test
{
    public test()
    {
        System.Net.HttpListener httpListener = new System.Net.HttpListener();
        httpListener.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous;
        httpListener.Prefixes.Add(“https://*:443/“);
        httpListener.Start();
        new System.Threading.Thread(new System.Threading.ThreadStart(delegate
        {
            while (true)
            {
                try
                {
                    System.Net.HttpListenerContext httpListenerContext = httpListener.GetContext();
                    new System.Threading.Thread(new System.Threading.ParameterizedThreadStart((input) =>
                    {
                        System.Net.HttpListenerContext ctx = (System.Net.HttpListenerContext)input;
                        System.Net.HttpListenerRequest request = ctx.Request;
                        string pram = request.QueryString[“Data“];//Get入参 
                        string responseMessage = string.Empty;//返回值
                        if (!string.IsNullOrEmpty(pram))
                        {
                            //Get入参,url解密
                            pramOrg = pram;
                            pram = System.Web.HttpUtility.UrlDecode(pram);
                        }

                        //POST入参
                        if (request.HttpMethod == “POST“)
                        {
                            isPost = true;
                            //处理业务请求
                            StreamReader reader = new StreamReader(request.InputStream Encoding.UTF8);
                            pram = reader.ReadToEnd();
                            reader.Close();
                            reader.Dispose();
                        }

                        #region 业务处理
                        try
                        {
                            //业务处理
                            responseMessage = “业务结果“;
                        }
                        catch (Exception ex)
                        {
                            //异常处理
                            responseMessage = ex.Message;
                        }
                        #endregion 业务处理
                        #region 返回给调用者
                        //输出类型
                        httpListenerContext.Response.ContentType = “text/html; charset=UTF-8“;
                        //返回状态
                        httpListenerContext.Response.StatusCode = 200;
                        //设置授权,尝试解决Jquery跨域问题
                        //httpListenerContext.Response.Headers[“Access-Control-Allow-Origin“] = “*“;
                        //httpListenerContext.Response.Headers[“Access-Control-Allow-Methods“] = “GETPOST“;
                        //httpListenerContext.Response.Headers[“Access-Control-Max-Age“] = “1000“;
                        try
                        {
                            //输出界面内容
                    

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件     296071  2019-09-05 17:57  HTTPS证书创建+绑定端口+C#程序监听.pdf

     文件       3970  2019-09-05 17:59  test.cs

----------- ---------  ---------- -----  ----

               300041                    2


评论

共有 条评论