13

There are a lot of questions on this topic, but - they gave me no answer.

As from advices - there is one to set ServicePointManager.Expect100Continue = false. But it is not acceptable because this will be a module, asynchroniously working along with dozen of others. So acceptable solution - is per-connection property. There are advices how to set this, but it doesn't seem to be working.

Here is the code:

var conuri = new Uri(connectionString);
var sp = ServicePointManager.FindServicePoint(conuri);
sp.Expect100Continue = false;

_request = (HttpWebRequest)WebRequest.Create(conuri);
_request.ContentType = "text/xml";
_request.Method = "POST";

_request.ContentLength = dataToSend.Length;
requestStream = _request.GetRequestStream();
requestStream.Write(dataToSend, 0, dataToSend.Length);

Problem is, that at the point "requestStream.Write" - header Expect: 100-continue is still added, but it shouldn't according to advice I've read here: C# Expect100Continue header request.

Community
  • 1
  • 1
Hikiko
  • 309
  • 1
  • 2
  • 12

2 Answers2

32

You can do it this way :

_request.ServicePoint.Expect100Continue = false;

This will disable the Expect: 100-continue for a particular HttpWebRequest instance.

Parimal Raj
  • 20,189
  • 9
  • 73
  • 110
0

When this property is set to true, client requests that use the POST method expect to receive a 100-Continue response from the server to indicate that the client should send the data to be posted. This mechanism allows clients to avoid sending large amounts of data over the network when the server, based on the request headers, intends to reject the request.

ServicePointManager.Expect100Continue = true;