Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expect: 100-continue

Tags:

c#

http

post

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.

like image 684
Hikiko Avatar asked Mar 11 '13 14:03

Hikiko


People also ask

What is expect 100 continue?

The client will 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.

How do you get a 100 status code?

The 100 Continue status code means that the initial part of the request has been received by the server and that the client should proceed with the request or ignore the response if the request has already finished.

What is expect in a request?

The Expect HTTP request header indicates expectations that need to be met by the server to handle the request successfully.


1 Answers

You can do it this way :

_request.ServicePoint.Expect100Continue = false;

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

like image 87
Parimal Raj Avatar answered Sep 25 '22 15:09

Parimal Raj