Error (HttpWebRequest): Bytes to be written to the stream exceed the Content-Length bytes size specified

后端 未结 2 1538
Happy的楠姐
Happy的楠姐 2020-12-18 22:57

I can\'t seem to figure out why I keep getting the following error:

Bytes to be written to the stream exceed the Content-Length bytes size specified.
         


        
2条回答
  •  南方客
    南方客 (楼主)
    2020-12-18 23:40

    There are three possible options

    • Fix the ContentLength as described in the answer from @rene

    • Don't set the ContentLength, the HttpWebRequest is buffering the data, and sets the ContentLength automatically

    • Set the SendChunked property to true, and don't set the ContentLength. The request is send chunk encoded to the webserver. (needs HTTP 1.1 and has to be supported by the webserver)

    Code:

    ...
    request.SendChunked = true;
    using (Stream writeStream = request.GetRequestStream())
    { ... }
    

提交回复
热议问题