webclient and expect100continue

后端 未结 2 773
小蘑菇
小蘑菇 2021-02-14 21:39

What is the best way to set expect100continue when using WebClient(C#.NET). I have this code below, I still see 100 continue in the header. Stupid apache still complains with 50

2条回答
  •  迷失自我
    2021-02-14 22:38

    The only way to do this is to create an override.

       public class ExpectContinueAware : System.Net.WebClient
        {
            protected override System.Net.WebRequest GetWebRequest(Uri address)
            {
                System.Net.WebRequest request = base.GetWebRequest(address);
                if (request is System.Net.HttpWebRequest)
                {
                    var hwr = request as System.Net.HttpWebRequest;
                    hwr.ServicePoint.Expect100Continue = false;
                }
                return request;
            }
        }
    

    This works perfect.

提交回复
热议问题