Advertisement
Guest User

Untitled

a guest
Jul 20th, 2019
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.70 KB | None | 0 0
  1. using System;
  2. using System.Collections.Specialized;
  3. using System.IO;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading;
  7.  
  8. namespace WraithSubmitter
  9. {
  10. class CaptchaSolveTextCaptcha
  11. {
  12. public static string SolveTextCaptcha(string apiKey, string theQuestion, out string result) {
  13. string postUrl = "https://2captcha.com/in.php";
  14. var response = string.Empty;
  15. result = string.Empty;
  16. try
  17. {
  18. using (var client = new WebClient())
  19. {
  20. var values = new NameValueCollection
  21. {
  22. ["key"] = apiKey,
  23. ["method"] = "POST",
  24. ["textcaptcha"] = theQuestion
  25. };
  26. var res = client.UploadValues(postUrl, values);
  27. response = Encoding.Default.GetString(res);
  28. }
  29. //Helpers.ReturnMessage(apiKey + " > " + theQuestion + " > " + result);
  30. //Helpers.ReturnMessage("Response: " + response);
  31. if (response.Substring(0, 3) == "OK|")
  32. {
  33. string captchaID = response.Remove(0, 3);
  34. for (int i = 0; i < 24; i++)
  35. {
  36. WebRequest getAnswer = WebRequest.Create("https://2captcha.com/res.php?key=" + apiKey + "&action=get&id=" + captchaID);
  37. using (WebResponse answerResp = getAnswer.GetResponse())
  38. using (StreamReader answerStream = new StreamReader(answerResp.GetResponseStream()))
  39. {
  40. string answerResponse = answerStream.ReadToEnd();
  41.  
  42. if (answerResponse.Length < 3)
  43. {
  44. result = answerResponse;
  45. } else {
  46. if (answerResponse.Substring(0, 3) == "OK|")
  47. {
  48. result = answerResponse.Remove(0, 3);
  49. break;
  50. } else if (answerResponse != "CAPCHA_NOT_READY"){
  51. //result = answerResponse;
  52. //return result;
  53. }
  54. }
  55. }
  56. Thread.Sleep(5000);
  57. }
  58. }
  59. } catch (Exception ex) {
  60. Helpers.ReturnMessage("TEXT CAPTCHA:\n\n" + ex.Message);
  61. }
  62. return result;
  63. }
  64.  
  65. } // End.
  66.  
  67. } // End.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement