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

╄→尐↘猪︶ㄣ 提交于 2019-12-01 02:41:35

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); 

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();

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>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!