【问题标题】:How to get the return value in a respone call back如何在响应回调中获取返回值
【发布时间】:2023-02-09 18:13:31
【问题描述】:
         public void Login(string LoginName,string username,string password)
            {
                RequestHeader contentTypeHeader = new RequestHeader
                {
                    Key = "Content-Type",
                    Value = "application/json"
                };
                JsonData data = new JsonData();
                data["username"] = username;
                data["password"] = password;
                StartCoroutine(NetworkManage.Instance.HttpPost(tempapiConfig[LoginName], data.ToJson(), (r) => OnRequestLoginComplete(r), new List<RequestHeader>
                {
                    contentTypeHeader
                }));
            }
// what I want to get here is bool a= r.respone
     bool OnRequestLoginComplete(Response response)
        {
            Debug.Log($"Status Code: {response.StatusCode}");
            Debug.Log($"Data: {response.Data}");
            Debug.Log($"Error: {response.Error}");
            return true;
        }

是否有可能从 r 获取返回值,因为响应是在 Http.Post.虽然我可以调试状态代码,但我想返回一个 true 以便用户可以转到下一页

【问题讨论】:

  • 好吧,在OnRequestLoginComplete 中做任何你需要做的事情。我想结果在response.Data 中的某个地方......可能是你必须反序列化的一些 JSON?

标签: c# unity3d lambda


【解决方案1】:

返回基于response.StatusCode验证的布尔值。

 if (response.StatusCode == HttpStatusCode.OK)
     return true;
    else 
     return false;

【讨论】:

    【解决方案2】:

    您的示例不完整,我不确定它是否是您想要的,但也许可以尝试返回类似的内容:

    return (int)r.StatusCode == 200

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 1970-01-01
      • 1970-01-01
      • 2019-10-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-07
      • 1970-01-01
      相关资源
      最近更新 更多