這是推動我堅果:爲什麼我在執行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