这是推动我坚果:为什么我在执行HTTP POST时耗尽流的字节?
WebRequest request = WebRequest.Create(url);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = Encoding.UTF8.GetByteCount(data);
Stream reqs = request.GetRequestStream();
StreamWriter stOut = new StreamWriter(reqs, Encoding.UTF8);
stOut.Write(data);
stOut.Flush();
,我感到我已经用完流中的字节的例外......但我已经使用了相同的编码得到的字节数!
使用ASCII这不会失败。 这是因为Windows喜欢添加的UTF-8 BOM吗?
如果你只是把'.ContentLength ='赋值出去了会发生什么? AFAIK应该在发送请求之前自动确定“ContentLength”。 – dtb 2009-11-18 21:30:25
跳过.ContentLength赋值工作。 – Broam 2009-11-18 22:25:13