I have program that later needed ability to broadcast an webpage, it basically works, however, only way it can be accessed is from the same machine that program is running on, client says and I agree with him that for our use case there might be need for it to be accessible from other devices in the LAN
The code:
using System;
using System.Net;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var web = new HttpListener();
web.Prefixes.Add("http://localhost:10001/");
web.Start();
var context = web.GetContext();
var response = context.Response;
const string responseString = "<html><body>Hello world</body></html>";
var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
var output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
output.Close();
web.Stop();
Console.ReadKey();
}
}
}
I can connect with address localhost:10001, but when using my local IP + :10001 I get
400 BAD REQUEST, invalid hostname
in browser both on same computer and other devices
Ok, maybe just change address mentioned in code to local IP + :10001?
using System;
using System.Net;
namespace ConsoleApp1
{
class Program
{
static void Main(string[] args)
{
var web = new HttpListener();
web.Prefixes.Add("http://192.168.0.12:10001/");
web.Start();
var context = web.GetContext();
var response = context.Response;
const string responseString = "<html><body>Hello world</body></html>";
var buffer = System.Text.Encoding.UTF8.GetBytes(responseString);
response.ContentLength64 = buffer.Length;
var output = response.OutputStream;
output.Write(buffer, 0, buffer.Length);
output.Close();
web.Stop();
Console.ReadKey();
}
}
}
No, when I run it an exception is thrown
access denied
in the line web.Start();
I use Windows 10 Pro x64 and latest Firefox, recently updated solutions .NET version to latest
Yes there have been similar questions but they are way too old to trust and they involve using different Windows tools which isn't best solution for plug and play program, fix in code or pointing out what I have done wrong would be perfect, thanks in advance!