stream.length'抛出了'system.notsupportedexception'类型的异常 [英] stream.length' threw an exception of type 'system.notsupportedexception'

查看:861
本文介绍了stream.length'抛出了'system.notsupportedexception'类型的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我收到错误

Hi in the below code I am receiving error

"stream.length' threw an exception of type 'system.notsupportedexception'"



我尝试过使用MemoryStream但仍然是一样吗?

什么我错过了????


I have tried using MemoryStream but still its the same??
What i am missing????

protected void Button1_Click(object sender, EventArgs e)
{
    string encodedURL = "http://abc.com/psms/servlet/psms.Eservice2";

    HttpWebRequest objRequest = (HttpWebRequest)WebRequest.Create(encodedURL);

    try
    {
        string xmlstr = "data=<!DOCTYPE REQUESTCREDIT SYSTEM \"http://127.0.0.1:80/ps/dtd/request.dtd\"><requestcredit username="\"abc\"" password="\"abc\""></requestcredit>&action=test";

        objRequest.Method = "POST";
        ASCIIEncoding objEncoding = new ASCIIEncoding();
        byte[] objBytes = objEncoding.GetBytes(xmlstr);
        objRequest.Timeout = 6000;
        objRequest.ContentType = "application/x-www-form-urlencoded";
        objRequest.Headers.Add("Accept-Encoding", "gzip, deflate");
        objRequest.ContentLength = objBytes.Length;
        objRequest.KeepAlive = true;

        //objRequest.ServicePoint.ConnectionLimit = GlobalVariable.connectionLimit;
        Stream strm = objRequest.GetRequestStream();
        strm.Write(objBytes, 0, objBytes.Length);
        strm.Flush();
        strm.Close();

        //ServicePointManager.DefaultConnectionLimit = GlobalVariable.connectionLimit;
        using (HttpWebResponse WebResponse = (HttpWebResponse)objRequest.GetResponse())
        {
            Stream responseStream = default(Stream);
            responseStream = WebResponse.GetResponseStream();
            if ((WebResponse.ContentEncoding.ToLower().Contains("gzip")))
            {
                responseStream = new System.IO.Compression.GZipStream(responseStream, System.IO.Compression.CompressionMode.Decompress);
            }
            else if ((WebResponse.ContentEncoding.ToLower().Contains("deflate")))
            {
                responseStream = new System.IO.Compression.DeflateStream(responseStream, System.IO.Compression.CompressionMode.Decompress);
            }

            StreamReader reader = new StreamReader(responseStream, System.Text.Encoding.Default);
            Response.Output.Write(reader.ReadToEnd());
            reader.Close();
            WebResponse.Close();
        }
    }
    catch (Exception ex)
    {
        throw ex;
    }
    finally
    {

    } objRequest.Abort();
}

推荐答案

我遇到了同样的问题。

我在谷歌搜索和绑定许多解决方案但没有任何效果。

最后我只是在请求中将我的URL链接更改为https://并且它有效!
I had the same problem.
I was googling and tying many of solutions but nothing worked.
At the end i just changes my URL links to "https://" in request and it worked!


这篇关于stream.length'抛出了'system.notsupportedexception'类型的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆