0
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;
}

我得到一个例外,说

此流不支持查找操作。

有哪些可能的解决方案?此代码运行了一段时间,并在一段时间后给出了操作已超时的错误消息。

4

0 回答 0