我正在尝试向Web服务器POST一些内容。
System.Net.HttpWebRequest EventReq = (System.Net.HttpWebRequest)System.Net.HttpWebRequest.Create("url");
System.String Content = "id=" + Id;
EventReq.ContentLength = System.Text.Encoding.UTF8.GetByteCount(Content);
EventReq.Method = "POST";
EventReq.ContentType = "application/x-www-form-urlencoded";
System.IO.StreamWriter sw = new System.IO.StreamWriter(EventReq.GetRequestStream(), System.Text.Encoding.UTF8);
sw.Write(Content);
sw.Flush();
sw.Close();
看起来还好,我正在根据编码数据的大小设置内容长度... 无论如何,在sw.flush() 失败,显示“要写入流中的字节数超过指定的Content-Length大小”
StreamWriter是否在我不知道的情况下进行了一些魔法?有没有办法可以窥探StreamWriter正在做什么?