How do I test HttpListener() using localhost?

4k Views Asked by At

I'm working on an app that uses HttpListener() extensively. So far I've been doing all my testing on an actual network, but I'm pretty sick of this now.

I've tried the usual suspects (localhost, 127.0.0.1) with the correct port, but nothing happens.

Is there a setting in Windows somewhere? (Is it obvious I'm a *nix boy normally?)

2

There are 2 best solutions below

5
On BEST ANSWER

Both localhost and 127.0.0.1 should work fine.

I suspect you have a firewall (such as Windows Firewall) that's preventing connections on your local box. Disable it while you're doing your testing.

0
On

Http.sys (which underpins HttpListener) dies not allow access by default unless you are running as an admin. You can enable this using httpcfg (xp) or netsh (vista, win7 etc).

See also this question

This is separate to the firewall; for external connections you will also need to open a small hole in the firewall.