System.Net.ProtocolViolationException: You must write ContentLength bytes to the request stream before calling [Begin]GetResponse

前端 未结 3 661
隐瞒了意图╮
隐瞒了意图╮ 2021-01-07 23:42

I am getting the

\"System.Net.ProtocolViolationException: You must write ContentLength bytes to the request stream before calling [Begin]GetResponse\

相关标签:
3条回答
  • 2021-01-08 00:19

    Your code should work for .NET 2.0 From 4.0 and up you should close the stream after writing:

    dataStream = Webrequest.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    datastream.Close();
    
    0 讨论(0)
  • 2021-01-08 00:23

    This finally worked by using:

    using (dataStream = Webrequest.GetRequestStream())
    {
       dataStream.Write(byteArray, 0, byteArray.Length);
    }
    

    Instead of:

    dataStream = Webrequest.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length); 
    
    0 讨论(0)
  • 2021-01-08 00:35

    Check to verify that your server is set up to accept large files. You may find that you are running into the 4 meg default limit.

    Add the following to your web.config file for larger file uploading:

    <system.webServer>
        <security>
            <requestFiltering>
                <requestLimits maxAllowedContentLength="104857600" />
            </requestFiltering>
        </security>
    </system.webServer>
    
    0 讨论(0)
提交回复
热议问题