资源简介
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
- 上一篇:实现UDP可靠文件传输
- 下一篇:基于asp.net c#在线答题页面
相关资源
- C# HTTP Get Post Demo
- fiddlercoreCapture.zip 用 .NET C# 实现 HTTP
- 最新版 Best HTTP v1.11.0.unitypackage
- 通过http协议上传文件
- ssleay32.dll 包括X64X86
- C# HttpWebRequest动态调用WebApi、WCF、We
- Q692791问题的回答,https://ask.csdn.net/
- C#版protobuf如何实现http方式二进制传输
- C#北大刷课工具
- C#实现HTTP GET和POST 样例代码
- C# Winform 简单实现Http
- HttpMonitor的完整源代码,方便获取re
- C#(Csharp)多线程HTTP并发请求(Http
- C#使用HttpClient
- WCF 解析 HTTP Multipart Form Data
- c# http接口设计及调用demo
- C# winhttp 封装类
- C# WEB/HTTP大文件与文件夹上传2
- asp.net c# http https 代理服务器源码
- C#开发webservice接口,对客户端post服务
- c#实现HttpClient拼接multipart/form-data形式
- Http APi 测试工具
- C#服务器推技术http长连接的应用
- C#HttpWebRequest大文件断点续传类
- C# asp.net http HttpWebRequest模拟浏览器请
- winform程序仿迅雷
- HttpHelper万能框架V2.4.zip
- 接收发送HTTP报文
- 如何在WPF应用程序中通过HttpClient调用
- C# HttpHelper.cs
评论
共有 条评论