HTTP POST Returns Error: 417 Expectation Failed.
System.Net.HttpWebRequest adds the header 'HTTP header "Expect: 100-Continue"' to every request unless you explicitly ask it not to by setting this static property to false:
System.Net.ServicePointManager.Expect100Continue = false;
Some servers choke on that header and send back the 417 error you're seeing.
Give that a shot.
WCF: The remote server returned an error: (417) Expectation Failed
After some weeks of research I could now find a solution.
create a custom MessageHandlerBehavior and DelegatingHandler (please look at https://justsimplycode.com/2019/11/02/disable-header-100-continue-in-net-core-wcf-client/)
use the custom MessageHandlerBehavior and set ExpectContinue to false:
var handlerFactoryBehavior = new HttpMessageHandlerBehavior();
handlerFactoryBehavior.OnSending = (message, token) =>
{
message.Headers.ExpectContinue = false;
return null;
};
var channelfactory = new SearchServiceClient(binding, endpoint);
channelfactory.ClientCredentials.ClientCertificate.SetCertificate(...);
channelfactory.Endpoint.EndpointBehaviors.Add(handlerFactoryBehavior);
The request failed with HTTP status 417: Expectation Failed - Using Web Services
This suggests that the problem is a proxy server that does not support a 100-continue response from the server, and shows code for resolving it. This would explain why it works on another network.
Since you are unlikely to convince your ISP to change their practice (no harm in a request though), you should turn off the behavior of sending a 100-Continue as the link suggests by either:
Putting this code before an web request:
System.Net.ServicePointManager.Expect100Continue = false;
Or, adding the following lines to the applications configuration file as a child of the <configuration>
tag:
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
C#/Restsharp: HTTP Error 417 Expectation failed
Putting the XML code above to every App.config
within my solution helped.
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>
The request failed with HTTP status 417: Expectation failed
The issue seems to be with the config on the mifi and not the Verizon network itself. We recently switched APNs and when a mifi connects to the Verizon network it is supposed to update automatically. Sometimes the mifi will fail to update the APN setting and that is when we get this error message. There are two ways I have found to fix this issue. The first and easier is to log into the mifi and manually update the setting. If you are dealing with a user who is not tech savvy and walking them through logging into the mifi will not work you can call the Verizon wireless enterprise help desk and have them remove the feature set from the mifi, add the features back, and then pull the battery from the mifi and power cycle it, this will make the mifi request the configuration settings again.
417: Expectation Failed on HTTPPost
The equivalent fix to prevent the request from using "expect continue" seems to be this:
httpPostInstance.getParams().setParameter(
CoreProtocolPNames.USE_EXPECT_CONTINUE,
Boolean.FALSE);
I found this at http://hc.apache.org/httpcomponents-client-ga/tutorial/html/fundamentals.html under 1.6.1.
Related Topics
Why Is Linq .Where(Predicate).First() Faster Than .First(Predicate)
How to Use a C# Class Library in a Project
Recommendations on Parsing .Eml Files in C#
Start May Not Be Called on a Promise-Style Task. Exception Is Coming
With Unity How to Inject a Named Dependency into a Constructor
How Is Memory Allocated for a Static Variable
A Textbox/Richtextbox That Has Syntax Highlighting? [C#]
Any Way to Turn the "Internet Off" in Windows Using C#
How to Check If Int Is Legal Enum in C#
ASP.NET MVC 3: Override "Name" Attribute with Textboxfor
How to Register a .Net Dll File in the Gac
Casting VS Converting an Object Tostring, When Object Really Is a String
Why Do Some C# Lambda Expressions Compile to Static Methods
Winforms Issue - Error Creating Window Handle
Rotate a Point by Another Point in 2D
How to Create Custom Propertygrid Editor Item Which Opens a Form
When to Use Enums, and When to Replace Them with a Class with Static Members
How to Force C# .Net App to Run Only One Instance in Windows