我有以下代码:流不可读 - 没有处理,为什么这不起作用?
// 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