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:
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);
Related posts:
- Real-time Data Delivery: HTTP Streaming Versus PubSubHubbub
- How to make a cross domain web request with SilverLight 2
- Using Fiddler to trick Silverlight into allowing a crossdomain Web Request
- Adding a real-time "Who’s shopping?" widget to an ASP.NET Web App
- Glug, Glug: Guzzle Ayup a Hosted PubSubHubbub Hub Service
About Phil Leggetter
My name is Phil Leggetter and I'm a Developer Evangelist at Pusher, a Real-Time Web Software and Technology Evangelist and Consultant, software engineer, team leader, line manager, micropreneur, product developer, Twitter user and a keen user of social media. For more information see the About Phil Leggetter page.
Social
Tags
.NET Ajax API APIs ASP.NET MVC Bing Blogging C# cloud comet Community DataSift Facebook Google Hardware http streaming ian sanders ideas Internet JavaScript Kwwika Life Mapping Microsoft Mobile Phones pubsubhubbub pusher real-time real-time data real-time push real-time web realtime RSS RTRIA Scotland silverlight Social Media Software Development Superfeedr truly real-time truly real-time web Twitter web 2.0 websockets Whinge









