开发者社区> 问答> 正文

OSS求助,GetObject在Unity中使用空指针异常

如题,我将2.3的DLL放在Unity(4.6和5.4)中测试使用,和demo中使用同样的代码和高权限用户参数(这里我保证参数正确),当调用到GetObject会出现错误;在demo中运行正常。。



    public static void GetObject()
    {
        try
        {
            //client.PutObject(bucketName, key, fileToUpload);
            var client = new OssClient("http://oss-cn-shanghai.aliyuncs.com", "参数", "参数");
            var result = client.GetObject("参数", "参数"); //在这里出错


            using (var requestStream = result.Content)
            {
                using (var fs = File.Open("C:/Users/Administrator/Desktop" + "/DataGetTemplateR.json", FileMode.OpenOrCreate))
                {
                    int length = 4 * 1024;
                    var buf = new byte[length];
                    do
                    {
                        length = requestStream.Read(buf, 0, length);
                        fs.Write(buf, 0, length);
                    } while (length != 0);
                }
            }
        }
        catch (OssException ex)
        {
            Debug.Log("Failed with error code: " + ex.ErrorCode + "; Error info: " + ex.Message + "\nRequestID:" + ex.RequestId + "\tHostID:{3}" +ex.HostId);
        }
    }


错误信息如下:





NullReferenceException: Object reference not set to an instance of an object
Aliyun.OSS.Common.Communication.HttpExtensions.AddInternal (System.Net.WebHeaderCollection headers, System.String key, System.String value)
Aliyun.OSS.Common.Communication.HttpFactory.SetRequestHeaders (System.Net.HttpWebRequest webRequest, Aliyun.OSS.Common.Communication.ServiceRequest serviceRequest, Aliyun.OSS.Common.ClientConfiguration configuration)
Aliyun.OSS.Common.Communication.HttpFactory.CreateWebRequest (Aliyun.OSS.Common.Communication.ServiceRequest serviceRequest, Aliyun.OSS.Common.ClientConfiguration configuration)
Aliyun.OSS.Common.Communication.ServiceClientImpl.SendCore (Aliyun.OSS.Common.Communication.ServiceRequest serviceRequest, Aliyun.OSS.Common.Communication.ExecutionContext context)
Aliyun.OSS.Common.Communication.ServiceClient.Send (Aliyun.OSS.Common.Communication.ServiceRequest request, Aliyun.OSS.Common.Communication.ExecutionContext context)
Aliyun.OSS.Common.Communication.RetryableServiceClient.SendImpl (Aliyun.OSS.Common.Communication.ServiceRequest request, Aliyun.OSS.Common.Communication.ExecutionContext context, Int32 retryTimes)

展开
收起
正义の馒头 2016-11-11 15:26:11 8828 0
4 条回答
写回答
取消 提交回答
  • ReOSS求助,GetObject在Unity中使用空指针异常
    自己搞了个OSS Unity SDK:github.com/Shirlman/aliyun-oss-unity-sdk
    2016-12-22 21:09:09
    赞同 展开评论 打赏
  • ReOSS求助,GetObject在Unity中使用空指针异常
    遇到了同问题,楼主解决了么?

    -------------------------

    ReOSS求助,GetObject在Unity中使用空指针异常
    只能用放弃OSS么?

    -------------------------

    回 楼主正义の馒头的帖子
    好吧,如果成功的话请回复一下
    2016-11-11 17:34:41
    赞同 展开评论 打赏
  • ReOSS求助,GetObject在Unity中使用空指针异常
    好吧 这种情况 是只能用HTTP URL了吧?

    -------------------------

    ReOSS求助,GetObject在Unity中使用空指针异常
    还有一种URL    OSS访问的URL方式,不过要组装签名(Signature),这个我也没看懂,没看见C#的组装方式,DLL在unity用还要报错,
    我打算直接让后台看了 ,正好后台也是python。打算让后台直接组装好完整的URL返回给客户端,再自己请求OSS服务器试试。

    -------------------------

    ReOSS求助,GetObject在Unity中使用空指针异常
    可以了
    2016-11-11 17:04:11
    赞同 展开评论 打赏
  • ReOSS求助,GetObject在Unity中使用空指针异常
    Unity  我们暂时不支持
    2016-11-11 16:53:59
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载