Google Calendar .NET API – HTTP 417 Error
I never even knew what a 417 error was until today. Apparently it’s an “Expectation Failed” error. It’s rare, to say the least. In my 15+ years of working with HTTP I’ve never come across it. I had to do some research to get this sorted out and while the information needed to diagnose and fix the problem existed elsewhere, it didn’t exist in one place. So I’m somewhat consolidating here and trying to provide links back to my original references.
What’s The History?
So here’s the skinny on the issue. There is a piece of an HTTP request called “Expect-100″ which tells a client making a request to first confirm that things are working, and if so to continue with the rest of the request. The response from the server if everything is working is a response of “100″.
Now technically, you’re only supposed to send “Expect-100″ as true if the server is prepared to handle it [reference]. Depending on the server setup, this may or may not break things. With more focus on web services, there’s more focus on the intricate settings that go into serving them (it’s not all just web browsers and strawberry jam nowadays, y’know).
What’s The Issue?
Since there is more focus on making sure things are done correctly, many services (Twitter and Google’s APIs are among them – [reference]) have decided that their HTTP requests should be properly formed. With the amount of traffic they generate, who can blame them. However, Microsoft’s .NET by default includes “Expect-100″ as “true” in all of its requests. So using .NET to do something with those API’s can cause a nasty and hard to track down 417 error. Fiddler to the rescue, right?
What’s The Fix?
Luckily, the fix is pretty easy once you figure out how to do it. Before you make a service request, just add this line of code (C#):
System.Net.ServicePointManager.Expect100Continue = false;
That should fix things right up. Enjoy!
Didn't find any related posts :(