I have the following code that works great internally. However, if I try to access via the public IP address I get "HTTP Error 400. The request hostname is invalid."
$httpListener = New-Object System.Net.HttpListener
$httpListener.Prefixes.Add("http://localhost:5000/")
$httpListener.Prefixes.Add("http://127.0.0.1:5000/")
#$httpListener.Prefixes.Add("http://publicipaddress:5000/")
$httpListener.Start()
write-host "Listening..."
do {
$context = $httpListener.GetContext()
$context.Response.StatusCode = 200
$context.Response.ContentType = 'text/HTML'
$WebContent = Get-Content -Path "C:\fusion\scott\test.html" -Encoding UTF8
$EncodingWebContent = [Text.Encoding]::UTF8.GetBytes($WebContent)
$context.Response.OutputStream.Write($EncodingWebContent , 0, $EncodingWebContent.Length)
$context.Response.Close()
Write-Host "." -NoNewLine
} until ([System.Console]::KeyAvailable)
$httpListener.Close()
If I try to uncomment the public ip address line, I then get tons of errors, starting with
Exception calling "Start" with "0" argument(s): "The format of the specified network name is invalid."