后来我用来Unity版的HttpWebRequest 可以了,UnityWebRequest

后来我用来Unity版的HttpWebRequest 可以了,UnityWebRequest

GUI 关于Unity中使用HttpWebRequest 的问题

https://blog.csdn.net/yaoyutian/article/details/79558747

 

我再Unity中使用HttpWebRequest获取需要下载文件大小时出错,Error getting response stream (Write: The authentication or decryption has failed.): SendFailureUnityEngine.Debug:Log(Object)

代码如下
long GetLength(string url)
        {
            WebRequest request = null;
            long length = 0;
            try
            {
                request = WebRequest.Create(url);
                WebResponse respone = request.GetResponse();
                length = respone.ContentLength;
                //request.Abort();
            }

            catch (WebException e)
            {
                Console.WriteLine("error : " + e.Message);
                isStop = true;
            }
            finally
            {
                if (request != null) request.Abort();
            }
            return length;
        }


我有尝试用window窗体项目去做,同样的代码是没有问题的,但是Unity就是不行
 

我是参考http://blog.csdn.net/wangxiong_zh/article/details/50472680这个做的,你可以跟你的对比一下

 

我参考了一下你连接那边的方式 但是在HttpWebResponse response = req.EndGetResponse(ar) as HttpWebResponse;这里 仍然会有那个问题 我不清楚是什么原因造成的

 

代码肯定是没问题的,我试过。你那边报什么错?

Error getting response stream (Write: The authentication or decryption has failed.): SendFailureUnityEngine.Debug:Log(Object) 这个问题发送失败,
我是5.4.2 5.6.1两个版本都试过,所以我想知道是不是什么配置导致的,
因为我在网上看到很多都是用的  WebResponse respone = request.GetResponse();这种方法没有问题的

 

       public static string stringToAudio(string serverURL, string fileName)
        {

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(serverURL)); request.Timeout = 30000; request.Method = "GET"; using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
            {
                using (Stream stream = response.GetResponseStream())
                {
                    byte[] buffer = new byte[1024];
                    FileStream fs = new FileStream(fileName, FileMode.Create, FileAccess.Write); int count = -1; while (count != 0) { count = stream.Read(buffer, 0, buffer.Length); fs.Write(buffer, 0, count); }
                    fs.Flush(); fs.Close();
                }
            }
            return fileName;
        }

我的也报错,Unity2017,同样的在vs控制台运行正常

 

后来我用来Unity版的HttpWebRequest 可以了,UnityWebRequest

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值