C# 流不支持查找操作
我试图在一个网站上发布,其中唯一需要的参数是“描述”。我相信这与我编码数据的方式有关。我是不是错过了什么/走错了方向C# 流不支持查找操作,c#,httpwebrequest,http-post,C#,Httpwebrequest,Http Post,我试图在一个网站上发布,其中唯一需要的参数是“描述”。我相信这与我编码数据的方式有关。我是不是错过了什么/走错了方向 string postData = String.Format("description=" + description + "&"); byte[] byteArray = Encoding.UTF8.GetBytes(postData); HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url); wr.M
string postData = String.Format("description=" + description + "&");
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
HttpWebRequest wr = (HttpWebRequest)WebRequest.Create(url);
wr.Method = WebRequestMethods.Http.Post;
wr.ContentLength = byteArray.Length;
wr.ContentType = "application/x-www-form-urlencoded";
Stream postStream = wr.GetRequestStream();
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
WebResponse response = await wr.GetResponseAsync();
HttpWebResponse webResponse = (HttpWebResponse)response;
using (var stm = response.GetResponseStream())
{
using (var reader = new StreamReader(stm))
{
var content = await reader.ReadToEndAsync();
reader.Close();
stm.Close();
return content;
}
}
您试图读取的流显然不支持查找。您还可以通过其属性以编程方式验证这一点
如果您希望在您可以查找的流中使用相同的数据,请考虑将当前流的全部内容读入<代码>字节[]/COD>缓冲区,然后构造一个缓冲区,供您使用<代码> StreamReader < /C> > .< /P>为什么不使用HtpCclipse?像这样使用
String.Format
似乎毫无意义。。。