Basic Authentication against the Superfeedr HTTP PubSubHubbub API using a .NET HttpWebRequest
It would appear that setting the Credentials property of a HttpWebRequest still leads to authentication failure against the Superfeedr HTTP PubSubHubbub API. This might be because the way the HttpWebRequest works is that it first waits to be challenged for credentials via a 401 (not authorized) and then replies with the authentication (more info include PreAuthenticate here).
So, this doesn't work:
string username = "username";
string password = "password";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("url-here");
request.Credentials = new NetworkCredential(username, password);
To work around this you need to force the authentication to be sent. I found the details of how to do this in a blog post by Ian Dykes here:
But for fullness here's the code:
string username = "username"; string password = "password"; byte[] authBytes = Encoding.UTF8.GetBytes(username + ":" + password.ToCharArray()); request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(authBytes);
Comments [0]