该流不允许搜索操作。有哪些可能的解决方案

时间:2013-10-28 08:13:08

标签: c# httpwebresponse

public static string MakePOSTWebREquest(string url, string contentType, string postData)
{
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
        if (!String.IsNullOrEmpty(contentType))
        {
            req.ContentType = contentType;
        }
        else
        {
            req.ContentType = "application/x-www-form-urlencoded";
        }
        req.Method = "POST";

        byte[] pbytes = Encoding.UTF8.GetBytes("list=");
        byte[] arr = Encoding.UTF8.GetBytes(postData);
        req.ContentType = "application/x-www-form-urlencoded";
        req.ContentLength = arr.Length + pbytes.Length;
        Stream stream = req.GetRequestStream(); //error stream does not allows seek operation
        stream.Write(pbytes, 0, pbytes.Length);
        stream.Write(arr, 0, arr.Length);
        stream.Close();

        HttpWebResponse webResp = (HttpWebResponse)req.GetResponse();

        //Now, we read the response (the string), and output it.
        Stream respStream = webResp.GetResponseStream();
        GZipStream zStream = new GZipStream(respStream, CompressionMode.Decompress);
        StreamReader reader = new StreamReader(zStream);
        string respData = reader.ReadToEnd();

        return respData;
}

我得到了一个说

的例外
  

此流不支持搜索操作。

有哪些可能的解决方案?此代码运行一段时间后一段时间后会显示操作已超时的错误消息。

0 个答案:

没有答案