我似乎无法弄清楚为什么我一直收到以下错误:
Bytes to be written to the stream exceed the Content-Length bytes size specified.
Run Code Online (Sandbox Code Playgroud)
在以下行:
writeStream.Write(bytes, 0, bytes.Length);
Run Code Online (Sandbox Code Playgroud)
这是在Windows窗体项目上.如果有人知道这里发生了什么,我肯定欠你一个.
private void Post()
{
HttpWebRequest request = null;
Uri uri = new Uri("xxxxx");
request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
XmlDocument doc = new XmlDocument();
doc.Load("XMLFile1.xml");
request.ContentLength = doc.InnerXml.Length;
using (Stream writeStream = request.GetRequestStream())
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] bytes = encoding.GetBytes(doc.InnerXml);
writeStream.Write(bytes, 0, bytes.Length);
}
string result = string.Empty;
request.ProtocolVersion = System.Net.HttpVersion.Version11;
request.KeepAlive = false;
try …Run Code Online (Sandbox Code Playgroud)