【问题标题】:WebClient.DownloadString throwing nullreference exceptionWebClient.DownloadString 抛出 nullreferenceexception
【发布时间】:2020-11-17 20:53:10
【问题描述】:

我正在尝试下载存储在特定网址的 XML 文件的内容。下面是代码

 WebClient wc = new WebClient();
 string data=wc.DownloadString(ghxuri);
 XElement xml = XElement.Parse(data);

ghxuri 是下载文件的链接,格式如下http://path/xml_file。 我可以通过单击链接下载文件,也可以从我的 c# 项目中运行它。但是当我尝试使用 webgl build 执行相同的功能时,它会抛出以下错误

NullReferenceException:对象引用未设置为对象的实例。

Rethrow as WebException:在 WebClient 请求期间发生异常。 在 System.Net.WebClient.DownloadDataInternal (System.Uri 地址,System.Net.WebRequest& 请求) [0x00000] in :0

(文件名:目前在 il2cpp 行中不可用:-1)

我无法理解 nullreferenceexception 的原因。

【问题讨论】:

标签: c# webclient nullreferenceexception unity-webgl


【解决方案1】:

这可能是您的 WebGl 无法访问互联网。由于安全隐患,这是意料之中的,.Net 网络将无法在 WebGl 中工作。有关更多详细信息和替代方案,请参阅以下链接。 https://docs.unity3d.com/Manual/webgl-networking.html

【讨论】:

    猜你喜欢
    • 2019-10-21
    • 2013-05-30
    • 2016-03-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多