private ApiManager getResponse() { if (this.isCancelled) return this; try { this.apiResponseXml = null; string req = this.builder.BuildQuery(); if (this.cacheString == null) { this.Log("Request string: " + req); ApiRequest request = new ApiRequest(); request.Timeout = this.Timeout; this.apiResponseString = request.Send(req); if (this.isCacheEnabled) { this.AppendCache(req, this.apiResponseString); } this.DebugMessage(this.apiResponseString); } else { this.apiResponseString = cacheString; this.DebugMessage("FROM CACHE: "+this.apiResponseString); } if (!this.apiResponseString.Equals("") || this.apiResponseString.Length > 0) { this.ResponseData(this.apiResponseString, (cacheString != null)); this.apiResponseXml = new XmlDocument(); this.apiResponseXml.LoadXml(this.apiResponseString); XmlNode isError = this.apiResponseXml.SelectSingleNode("/error"); if (isError == null) { this.MethodSuccessed = true; this.RequestCompleted(RequestResult.Success); } else { int code = Convert.ToInt32(isError.SelectSingleNode("error_code").InnerText); string msg = isError.SelectSingleNode("error_msg").InnerText; Hashtable ht = new Hashtable(); XmlNodeList pparams = isError.SelectNodes("request_params/param"); foreach (XmlNode n in pparams) { ht[n.SelectSingleNode("key").InnerText.ToString()] = n.SelectSingleNode("value").InnerText.ToString(); } this.RequestCompleted(RequestResult.Error); throw new ApiRequestErrorException(msg, code, ht); } //return this; } else { this.RequestCompleted(RequestResult.Error); throw new ApiRequestEmptyAnswerException("API Server returns an empty answer or request timeout"); } } catch (ApiRequestErrorException e) { if (e.Code == (int)ErrorCodes.CapthaRequired) { if (!this.isCancelled) { XmlUtils.UseNode(this.apiResponseXml.SelectSingleNode("/error")); this.CapthaRequired(XmlUtils.String("captcha_img"), XmlUtils.String("captcha_sid")); } //return this; } else throw new ApiRequestErrorException(e.Message, e.Code, e.ParamsPassed); } return this; }