I'm facing a problem here, with HttpListener.
When a request of the form
http://user:password@example.com/
is made, how can I get the user and password ? HttpWebRequest has a Credentials property, but HttpListenerRequest doesn't have it, and I didn't find the username in any property of it.
Thanks for the help.
You need to first enable Basic Authentication:
Then in your ProcessRequest method you could get username and password:
What you're attempting to do is pass credentials via HTTP basic auth, I'm not sure if the username:password syntax is supported in HttpListener, but if it is, you'll need to specify that you accept basic auth first.
Once you receive a request, you can then extract the username and password with:
Here's a full explanation of all supported authenitcation methods that can be used with HttpListener.
Get the
Authorization
header. It's format is as followsExample:
The username and password is colon-seperated (in this example,
Aladdin:open sesame
), then B64-encoded.