The header is a client header, not server. The server should support it correctly. As it slows down performance, this header is seldom used anymore and is not recommended. You don’t specify which framework version you are using for HttpClient, but core versions do not support the header on windows (because the lower layers don’t)
The .net clients - Channel Factory & HttpClient behaving differently for "Expect100Continue" header
I have WCF service hosted in a Custom Microsoft Web Server. I have tried to consume the services with TLS 1.3 and with Expect:100-Continue header by two .net provided clients.
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls13;
The above statement is common for both clients, because the server is supporting "Expect:100-Continue header" and TLS 1.3. The client I' running in a Windows 11 PC, so client also supporting TLS 1.3.
Client 1: :
HttpsTransportBindingElement myBinding = new HttpsTransportBindingElement();
myBinding.AuthenticationScheme = System.Net.AuthenticationSchemes.Basic;
TextMessageEncodingBindingElement textMessageEncoding = new TextMessageEncodingBindingElement();
textMessageEncoding.MessageVersion = MessageVersion.Soap12WSAddressingAugust2004;
CustomBinding binding = new CustomBinding(textMessageEncoding, myBinding);
EndpointAddress myEndpoint = new EndpointAddress("https://ip:port/MyService");
ChannelFactory<IMyService> myChannelFactory = new ChannelFactory<IMyService>(binding, myEndpoint);
myChannelFactory.Credentials.UserName.UserName = "admin";
myChannelFactory.Credentials.UserName.Password = "";
var wcfClient1 = myChannelFactory.CreateChannel();
var myResponse = wcfClient1.MyMethod();
Client 2 :
HttpClient client = new HttpClient();
string body = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/"><s:Body>;.....";
StringContent content = new StringContent(body, Encoding.UTF8, "text/xml");
var response = await client.PostAsync("https://ip:port/MyService", content);
My problem is - When with Client 1, In the server, the request is coming only with headers (no body) and the body is coming later. But with Client 2, from the first time itself the Header and Body is coming along with request.
Why this two .net clients behaving differently for "Expect100Continue" header ? Which client is honoring the "Expect100Continue" header ?
With TLS 1.2 option both client behave same, the first time itself request have both header and body.