简体   繁体   English

“UnityWebRequest”不包含“结果”的定义

[英]'UnityWebRequest' does not contain a definition for 'result'

When I use the code satable for the unity 2021 in the unity 2019.当我在 unity 2019 中使用代码 satable for unity 2021 时。

The console shows that控制台显示

'UnityWebRequest' does not contain a definition for 'result' and no accessible extension method 'result' accepting a first argument of type 'UnityWebRequest' could be found (are you missing a using directive or an assembly reference?) “UnityWebRequest”不包含“result”的定义,并且找不到接受“UnityWebRequest”类型的第一个参数的可访问扩展方法“result”(您是否缺少 using 指令或程序集引用?)

Bugs/problem:错误/问题:

if (req.result == UnityWebRequest.Result.ConnectionError || req.result == UnityWebRequest.Result.ProtocolError)

I expect I can use those code on unity 2019 with other codes and works.我希望我可以在 unity 2019 上将这些代码与其他代码和作品一起使用。

Simply consult the API!只需查阅 API!

result was added in version 2020.3. result在版本 2020.3 中添加。

Prior to that version simply follow the examples from the according version API eg 2019.4 API在该版本之前,只需遵循相应版本 API 中的示例,例如2019.4 API

You can eg simply check if there is any content in error您可以例如简单地检查是否有任何内容error

using (var webRequest = UnityWebRequest.Get(uri))
{
    yield return webRequest.SendWebRequest();

    if (!string.IsNullOrWhiteSpace(webRequest.error))
    {
        Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
        yield break;
    }

    Debug.Log(webRequest.downloadHandler.text);
}

or if you want to further differentiate isNetworkError (includes errors like no internet connection, host not reachable, DNS resolve error etc) and isHttpError (basically same as responseCode >= 400 )或者,如果您想进一步区分isNetworkError (包括无互联网连接、主机不可访问、DNS 解析错误等错误)和isHttpError (与responseCode >= 400基本相同)


If your question is about downwards compatibility but support both versions either stick to the pre-2020.3 way or use Conditional Compilation and do eg如果您的问题是关于向下兼容性但同时支持这两个版本,要么坚持 2020.3 之前的方式,要么使用条件编译,例如

#if UNITY_2020_3_OR_NEWER
    if(webRequest.result == UnityWebRequest.Result.ConnectionError || webRequest.result == UnityWebRequest.Result.ProtocolError)  
#else
    if(!string.IsNullOrWhiteSpace(webRequest.error))
#endif
    {
        Debug.LogError($"Error {webRequest.responseCode} - {webRequest.error}");
        yield break;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 找到模块 XXX,但不包含 package XXX - Module XXX found, but does not contain package XXX AWSa APIGatewayV2HTTPRequest 不包含 RequestContext - AWSa APIGatewayV2HTTPRequest does not contain RequestContext go:找到模块但不包含 package - go: module found but does not contain package SendGrid 模板不包含必需的占位符 - SendGrid Template does not contain required placeholders ECS 任务定义是否支持卷映射语法? - Does ECS task definition support volume mapping syntax? Firestore 规则是否区分大小写或我的路径是否包含错误? - Are firestore rules case sensitive or does my path contain an error? 尝试导入错误:“firebase/app”不包含默认导出(导入为“firebase”) - Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase') 深度链接不包含有效的必需参数 - Flutter 和 Firebase 动态链接 - Deep Link does not contain valid required params - Flutter with Firebase Dynamic Link 为什么.get() 会导致 TypeError:posts.get is not a function? - Why does .get() result in TypeError: posts.get is not a function? 为什么我的 fetch function 会导致 Expo 中出现“网络请求失败”? - Why does my fetch function result in a 'Network request failed' in Expo?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM