- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
好吧,如果我运行这个简化的代码片段,程序会剧烈崩溃,甚至不会抛出异常。
所以这是我之前所做的:
所以一切都应该正常吗?错误的!这让我发疯了好几个小时..
using System;
using System.Net;
using System.Text;
public class HttpListenerTest {
public static void Main(string[] args) {
Console.WriteLine("Initialize..");
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://*:8089/");
listener.Prefixes.Add("https://*:8443/");
listener.Start();
while (true) {
Console.WriteLine("Listening..");
HttpListenerContext context = listener.GetContext();
Console.WriteLine("Respond..");
byte[] bytes = Encoding.UTF8.GetBytes("works!");
context.Response.OutputStream.Write(bytes, 0, bytes.Length);
context.Response.OutputStream.Flush();
context.Response.OutputStream.Close();
context.Response.Close();
}
}
}
如果我运行此代码并在端口 8089 上发出 http 请求,一切都很好。 8443 上的 https 请求终止了进程,唯一发生的事情是“异常事件”( Screenshot here) 在 Debug模式下。
..用谷歌搜索丢失的文件名,得到 4 个不相关的结果。
我的知识已经用完了,真的需要 ssl 才能与监听器一起工作。
因此,如果您对此有任何经验或建议,请告诉我。
最佳答案
如果您需要快速修复本地主机(仅针对本地主机)
感谢 SushiHangovers 的评论,将缺少的环境变量“MONO_TLS_PROVIDER”设置为“btls”(BoringSSL)解决了这个问题。
$ MONO_TLS_PROVIDER=btls mono servertest.exe
如果您需要它在服务器上工作
感谢 Gusman,这里有一个简短易懂的指南,介绍如何使用 Nginx 管理 SSL 和向 Mono 服务器发送 Http 请求。
1.首先安装/设置Nginx
www.digitalocean.com/community/tutorials/how-to-install-nginx-on-ubuntu-16-04
2.然后安装Certbot
certbot.eff.org
3. 使用 Certbot 保护 Nginx
www.digitalocean.com/community/tutorials/how-to-secure-nginx-with-let-s-encrypt-on-ubuntu-16-04
4. 反向代理到您的 HttpListener 端口 ( taken from here )
4.1打开Nginx配置文件
$ sudo nano /etc/nginx/sites-available/default
4.2 注释掉默认的 try_files 行并指定反向代理设置
. . .
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
# try_files $uri $uri/ =404;
# Reverse proxy settings
include proxy_params;
proxy_pass http://localhost:8010;
}
. . .
并改变
server_name _;
到
server_name example.com www.example.com;
现在你应该可以开始了。
关于C# HttpListener 在 SSL 上完全失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46289016/
我一直在 Windows 服务应用程序中放置一个小型嵌入式 HTTP 服务器,用于监听来自网络上使用 HTTP 的其他设备的更新。 对于每个 HTTP 请求,处理请求/响应的代码会执行两次,我希望它只
我正在开发一个迄今为止使用 HttpListener 来提供小型独立 http 服务器的应用程序。但是,我最近发现 HttpListener 需要以管理员身份运行,这并不总是可行的。 最好的选择是什么
我正在开发一个具有 HttpListener 的应用程序。我的目标是让用户根据自己的选择关闭和打开监听器。我将 Listener 放在一个新线程中,但在中止该线程时遇到问题。我在某处读到,如果您尝试中
我创建了简单的 HttpListener 来监听端口 9090 并根据请求的 URL 将一些信息写入控制台。 但我卡住了 :( 我想到了多线程、基于事件的系统,但我没有设法用它做任何事情。 这是我作为
我正在编写一个控制台应用程序作为 httplistener 并通过 jquery 使用它,它的工作完全正确,但我想将其转换为 https,但我不知道步骤 这是我的代码希望大家能尽快解决 这是在 JSc
我的 c# httplistener 仅在我在本地网络中发送请求时捕获请求(来自使用本地 ip 的同一 wifi 上的机器)。 当我查看我的公共(public) ip(在 google 中使用“我的
我正在制作一个简单的网络服务器来提供 html、css、js 和图像(在 c# 中完成)。我正在使用 HttpListener,我可以让 html、javascript 和 css 文件正常工作。我只
我尝试在不使用 IIS 的情况下设置 Web 服务。 我知道我们可以使用 HttpListener 来创建简单的 http 服务器。我想知道它现在是否已被弃用,因为 WCF 似乎提供了更多高级功能。
我有一个应该监听 HTTP 请求的 Windows 服务。为此,我正在使用 HttpListener。该服务已成功完成其工作。但是,当服务设置为在系统启动时自动启动时,我的 HTTP 初始化有延迟。
我有一个基于 HttpListener 的小型本地 Web 服务器。服务器提供文件给本地客户端应用程序解包并写入文件到 response.OutputStream; 但有时文件(视频)很大,我不认为总
我正在通过尝试获取一个打开的随机端口(或一个不在 IpGlobalProperties.GetActiveTcpConnections() 中的端口)来创建一个 HttpListener。我遇到的问题
我正在开发一个广泛使用 HttpListener() 的应用程序。到目前为止,我一直在实际网络上进行所有测试,但我现在对此感到厌烦。 我用正确的端口尝试了通常的嫌疑人(本地主机,127.0.0.1),
我正在使用这段代码来实现 Http 服务器: public Server() { _httpListener = new HttpListener(); _ht
我必须实现一个小型 REST 服务器来管理远程数据库,没什么特别的。安全性不是关键问题,因为此服务器必须在 Intranet 环境中运行;我们只想过滤用户并将他们重定向到适当的资源。
我有几个 HttpListener 服务在同一台机器上使用不同的 URI(同一端口)。有没有办法让一个进程检测哪些其他服务正在运行并在同一台机器上注册为 HttpListeners?他们都共享这样的公
我正在编写一个类似于 HFS 的应用程序,它是一个 HTTP 文件服务器,在 HTML/CSS/JS 中具有自定义主题,我我希望能够在多个部分提供我的文件,因为大多数下载管理器通过多个连接连接到服务器
好吧,这是一个很长的问题,但我认为这是值得的。我们拥有的: 一个示例虚拟 C# 控制台应用程序,启动自托管的 owin ASP.Net WebAPI 服务(Microsoft.AspNet.Web
我必须建立一个 HttpListener 来等待客户端服务器发出的请求。我必须在端口 8088 上接收该请求并提取查询字符串。这是简单的部分。 我在 Windows 服务中运行 HttpListene
这个问题在这里已经有了答案: Handling multiple requests with C# HttpListener (3 个答案) 关闭 8 年前。 我有这个 HttpListener,它
我在这里遇到一个问题,与 HttpListener 有关。 当一个请求的形式 http://user:password@example.com/ 制作完成,如何获取用户名和密码?HttpWebRequ
我是一名优秀的程序员,十分优秀!