C# HttpListener The format of the specified network name is not valid
Asked Answered
H

2

6

I have this tiny piece of code where I try to add prefixes for my HttpListener:

listener = new HttpListener();
listener.Prefixes.Add("http://192.168.0.108:8088/");
listener.Start();

Which throws:

System.Net.HttpListenerException (0x80004005): The format of the specified network name is not valid

I've tried everything: turning off firewall, running as administrator, registering given URL with netsh http urlacl and yet, nothing has worked so far.

I checked with netstat if that address is open to use and it is. The weird thing about this is that I have been using this address for a long time until Windows 10 Fall Creators Update, since this update, only localhost is working.

Is there anything else that I forgot about or might try?

Heathenry answered 25/12, 2017 at 15:5 Comment(2)
Errors starting with 0x8 are invalid pointer or addresses. A listener can only be on local PC. So is the IP address of your pc 192.168.0.108?Hop
No, I checked that and my PC address is different, maybe another device in local network?Danndanna
U
13

You probably forgot to configure your system to listen for HTTP protocol communication coming from the specified IP address. Try running the following command to include it:

netsh http add iplisten 192.168.0.108

Once this is done, check the list of the addresses (in which your IP should now appear):

netsh http show iplisten

and then try to run your code again.

Upshaw answered 25/12, 2017 at 15:12 Comment(1)
Yes! Thanks a lot! I've changed my server's code to localhost prefix, but I also changed the client requests address to 192.168.0.108 and it works! Perfect!Danndanna
D
0

check 192.168.0.108 is ipv4 of your pc.

2 way to check this:

  • you can execute ipconfig in cmd and see all of the ipv4 addresses.
  • check in network properties:
  1. press windows+r and apen "ncpa.cpl"
  2. select Network goto Properties in Networking tab
  3. double click on Internet Protocol Version 4
  4. check Ip Address is: 192.168.0.108 or in advanced add 192.168.0.108 ip address
Dato answered 2/8 at 8:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.