10 |
10 |
using System.Diagnostics;
|
11 |
11 |
using System.IO;
|
12 |
12 |
using System.Net;
|
|
13 |
using System.Reflection;
|
13 |
14 |
using System.Net.Sockets;
|
14 |
15 |
using System.Text;
|
15 |
16 |
using System.Threading;
|
16 |
17 |
using System.Web;
|
|
18 |
using System.Security.Cryptography.X509Certificates;
|
17 |
19 |
|
18 |
20 |
namespace ServerApp.Connection
|
19 |
21 |
{
|
... | ... | |
36 |
38 |
string ip = GetLocalIPAddress();
|
37 |
39 |
Console.WriteLine("ip : " + ip);
|
38 |
40 |
HttpListener listener = new HttpListener();
|
39 |
|
//HttpListener server = new HttpListener();
|
40 |
|
listener.Prefixes.Add($"https://{ip}:{PORT}/");
|
41 |
|
//listener.Prefixes.Add($"http://localhost:{PORT}/");
|
42 |
|
|
43 |
|
listener.Start();
|
|
41 |
//HttpListener server = new HttpListener();
|
|
42 |
listener.Prefixes.Add($"https://*:{PORT}/");
|
|
43 |
//listener.Prefixes.Add($"http://*:{PORT}/");
|
|
44 |
|
|
45 |
// Set certificate via reflection ´, taken from https://github.com/dotnet/runtime/issues/27391
|
|
46 |
Type hepmType = Type.GetType("System.Net.HttpEndPointManager, System.Net.HttpListener");
|
|
47 |
Type heplType = Type.GetType("System.Net.HttpEndPointListener, System.Net.HttpListener");
|
|
48 |
MethodInfo getEPListener = hepmType.GetMethod("GetEPListener", BindingFlags.Static | BindingFlags.NonPublic);
|
|
49 |
FieldInfo heplCert = heplType.GetField("_cert", BindingFlags.NonPublic | BindingFlags.Instance);
|
|
50 |
object epl = getEPListener.Invoke(null, new object[] { "*", PORT, listener, true });
|
|
51 |
X509Certificate cert = new X509Certificate2("cert.p12", "changeit");
|
|
52 |
heplCert.SetValue(epl, cert);
|
|
53 |
|
|
54 |
listener.Start();
|
44 |
55 |
|
45 |
56 |
Console.WriteLine("Listening...");
|
46 |
57 |
|
Re #9009 fix https listener issue