35

I'm developing an app that for legacy code reasons I can't upgrade for the new HttpClient so I'm using HttpWebRequests.

In .NET 4 we could deactivate the Expect header (on posts requests) using ServicePoint.Expect100Continue property, but on WinRT it's not available.

How can this be accomplished on WinRT?

EDIT: System.Net.ServicePointManager.Expect100Continue is not available either.

DVD
  • 1,744
  • 3
  • 17
  • 34
  • You can't remove Expect from the request header collection? – Ben Feb 01 '13 at 02:27
  • No because it isn't there, the header is automatically added when I begin waiting for the response. – DVD Feb 01 '13 at 10:15
  • Have you tried to play with the ContinueTimeout (http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.continuetimeout.aspx) property, lke setting -1 or 0 or MaxValue. This seems to be the only related property supported by the WinRT version... (no ContinueDelegate, no Expect, no SendChunked, no ServicePoint) – Simon Mourier Feb 03 '13 at 17:36
  • ContinueTimeout with 0, -1 or int.maxvalue doesn't help – DVD Feb 03 '13 at 21:14

3 Answers3

62
var c = new HttpClient();
c.DefaultRequestHeaders.ExpectContinue = false;
Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114
Flatliner DOA
  • 6,128
  • 4
  • 30
  • 39
  • As I said I can't use httpclient – DVD Feb 03 '13 at 16:33
  • Sorry saw that after I posted. Unfortunately the code to modify the HttpWebRequest ExpectContinue property has been explicitly blocked. This is the only way to get rid of it. – Flatliner DOA Feb 04 '13 at 22:37
  • Unable to find property ExpectContinue: https://msdn.microsoft.com/en-us/library/windows/apps/windows.web.http.headers.httprequestheadercollection.aspx Am I reading a wrong document? – Hong Jun 08 '15 at 23:51
12

Put this is your webconfig.

<system.net>
  <settings> 
    <servicePointManager expect100Continue="false"/>  
  </settings> 
</system.net>

Also works! I use this in my webapplication. But answer above is equally as good!

Dan Atkinson
  • 11,391
  • 14
  • 81
  • 114
8bitcat
  • 2,206
  • 5
  • 30
  • 59
1

It seems the only option you have it to override BeginGetRequestStream. HttpWebRequest has a private method MakeRequest and in it the Expect100Continue header is added to the request header collection.

Radin Gospodinov
  • 2,313
  • 13
  • 14
  • How can I accomplish that? The HttpWebRequest class has an internal constructor... – DVD Feb 03 '13 at 21:20
  • 1
    I found a better solution. Did you try this: HttpWebRequest webRequest = ( HttpWebRequest ) WebRequest.Create( "http://something" ); webRequest.Method = "POST"; webRequest.ServicePoint.Expect100Continue = false; – Radin Gospodinov Feb 08 '13 at 06:16
  • that option is not available on winrt XD – DVD Feb 09 '13 at 15:31