private static async Task <string> ProcessTask(Client client, AnticaptchaTask task, string apikey) { AnticaptchaResult response; do { response = AnticaptchaApiWrapper.GetTaskResult(Host, apikey, task); if (response.GetStatus().Equals(AnticaptchaResult.Status.ready)) { break; } await Task.Delay(3000); } while (response != null && response.GetStatus().Equals(AnticaptchaResult.Status.processing)); if (response == null || response.GetSolution() == null) { client.ClientManager.LogCaller(new LoggerEventArgs("Unknown error occurred...", LoggerTypes.FatalError)); //Console.WriteLine("Response dump:"); //Console.WriteLine(response); } else { //Console.WriteLine("The answer is '" + response.GetSolution() + "'"); } return(response.GetSolution()); }
public static AnticaptchaResult GetTaskResult(string host, string clientKey, AnticaptchaTask task) { var jObj = new JObject(); jObj["clientKey"] = clientKey; jObj["taskId"] = task.GetTaskId(); try { dynamic resultJson = JsonPostRequest(host, "getTaskResult", JsonConvert.SerializeObject(jObj, Formatting.Indented)); var status = AnticaptchaResult.Status.unknown; try { status = resultJson.status.ToString().Equals("ready") ? AnticaptchaResult.Status.ready : AnticaptchaResult.Status.processing; } catch { // ignored } string solution; int? errorId = null; string errorCode = null; string errorDescription = null; double?cost = null; string ip = null; int? createTime = null; int? endTime = null; int? solveCount = null; try { solution = resultJson.solution.gRecaptchaResponse.ToString(); } catch { try { solution = resultJson.solution.text.ToString(); } catch { solution = null; } } try { errorId = resultJson.errorId; } catch { // ignored } try { errorCode = resultJson.errorCode; } catch { // ignored } try { errorDescription = resultJson.errorDescription; } catch { // ignored } try { cost = double.Parse(resultJson.cost.ToString().Replace(',', '.'), CultureInfo.InvariantCulture); } catch { // ignored } try { createTime = resultJson.createTime; } catch { // ignored } try { endTime = resultJson.endTime; } catch { // ignored } try { solveCount = resultJson.solveCount; } catch { // ignored } try { ip = resultJson.ip; } catch { // ignored } return(new AnticaptchaResult( status, solution, errorId, errorCode, errorDescription, cost, ip, createTime, endTime, solveCount )); } catch { // ignored } return(null); }