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:

http://devproj20.blogspot.com/2008/02/assigning-basic-authorization-http.html

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);

Permalink

| Leave a comment  »

Related posts:

  1. Real-time Data Delivery: HTTP Streaming Versus PubSubHubbub
  2. How to make a cross domain web request with SilverLight 2
  3. Using Fiddler to trick Silverlight into allowing a crossdomain Web Request
  4. Adding a real-time "Who’s shopping?" widget to an ASP.NET Web App
  5. Glug, Glug: Guzzle Ayup a Hosted PubSubHubbub Hub Service
Tagged with:
 
Set your Twitter account name in your settings to use the TwitterBar Section.