我有以下代碼:流不可讀 - 沒有處理,爲什麼這不起作用?
// Create POST data and convert it to a byte array.
string postData = "name=t&description=tt";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
using (StreamReader reader = new StreamReader(request.GetRequestStream()))
{
string s = reader.ReadToEnd();
}
當流量擊中使用(.....)語句,我得到以下異常:
流未讀
我想將整個請求流讀入一個字符串,沒有任何東西被關閉,所以代碼應該工作?
什麼是'request'?你在哪裏設定內容? – Cameron 2011-03-21 23:52:29
您不應該試圖寫入流嗎? – 2011-03-21 23:54:46
類似的情況已得到解答,並可能有所幫助,請參閱:http://stackoverflow.com/a/43981770/2791237 – 2017-05-15 14:19:09