コード例 #1
0
        private async Task <bool> HandleCaptchaError(HttpResponseMessage response)
        {
            var json = await response.Content.ReadAsStringAsync();

            var     jsonObject = JsonConvert.DeserializeObject(json) as JObject;
            JToken  captcha    = null;
            JToken  errors     = null;
            JObject first      = null;

            if (jsonObject.First != null)
            {
                first = (jsonObject.First as JProperty).Value as JObject;
            }

            if (first != null)
            {
                first.TryGetValue("captcha", out captcha);
                first.TryGetValue("errors", out errors);
                if (captcha != null)
                {
                    CaptchaIden = captcha.Value <string>();
                }

                if (captcha != null && errors != null)
                {
                    _userState.NeedsCaptcha = true;
                    Captcha = await _captchaProvider.GetCaptchaResponse(CaptchaIden);

                    if (Captcha == null)
                    {
                        throw new RedditException("captcha failed");
                    }
                    else
                    {
                        return(true);
                    }
                }
                else
                {
                    return(false);
                }
            }
            return(false);
        }