コード例 #1
0
ファイル: HttpClient.cs プロジェクト: thehrisworld/twtboard
        /**
         * <see cref="M:DeathByCaptcha.Client.Upload(byte[])"/>
         */
        public override Captcha Upload(byte[] img)
        {
            string boundary = BitConverter.ToString(
                (new SHA1CryptoServiceProvider()).ComputeHash(
                    Encoding.ASCII.GetBytes(DateTime.Now.ToString("G"))
                    )
                ).Replace("-", String.Empty);

            Hashtable args = this.Credentials;

            args["swid"] = Convert.ToString(Client.SoftwareVendorId);
            string[] rawArgs = new string[args.Count + 2];
            int      i       = 0;

            foreach (DictionaryEntry e in args)
            {
                string v = (string)e.Value;
                rawArgs[i++] = String.Join("\r\n", new string[] {
                    "--" + boundary,
                    "Content-Disposition: form-data; name=\"" + (string)e.Key + "\"",
                    "Content-Length: " + v.Length,
                    "",
                    v
                });
            }
            rawArgs[i++] = String.Join("\r\n", new string[] {
                "--" + boundary,
                "Content-Disposition: form-data; name=\"captchafile\"; filename=\"captcha.jpeg\"",
                "Content-Type: application/octet-stream",
                "Content-Length: " + img.Length,
                ""
            });

            byte[] hdr  = Encoding.ASCII.GetBytes(String.Join("\r\n", rawArgs));
            byte[] ftr  = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
            byte[] body = new byte[hdr.Length + img.Length + ftr.Length];
            hdr.CopyTo(body, 0);
            img.CopyTo(body, hdr.Length);
            ftr.CopyTo(body, hdr.Length + img.Length);

            Captcha c = new Captcha(this.Call(
                                        "captcha",
                                        body,
                                        "multipart/form-data; boundary=" + boundary
                                        ));

            return(c.Uploaded ? c : null);
        }
コード例 #2
0
        /**
         * <summary>Upload and wait for a CAPTCHA to be solved.</summary>
         * <param name="img">Raw CAPTCHA image.</param>
         * <param name="timeout">Solving timeout (in seconds).</param>
         * <returns>CAPTCHA if solved, null otherwise.</returns>
         */
        public Captcha Decode(byte[] img, int timeout)
        {
            DateTime deadline =
                DateTime.Now.AddSeconds(0 < timeout ? timeout : Client.DefaultTimeout);
            Captcha captcha = this.Upload(img);

            if (null != captcha)
            {
                while (deadline > DateTime.Now && !captcha.Solved)
                {
                    Thread.Sleep(Client.PollsInterval * 1000);
                    captcha = this.GetCaptcha(captcha);
                }
                if (captcha.Solved && captcha.Correct)
                {
                    return(captcha);
                }
            }
            return(null);
        }
コード例 #3
0
ファイル: Client.cs プロジェクト: prog-moh/twtboard
 /**
  * <summary>Report an incorrectly solved CAPTCHA.</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Report(Captcha captcha)
 {
     return this.Report(captcha.Id);
 }
コード例 #4
0
ファイル: Client.cs プロジェクト: prog-moh/twtboard
 /**
  * <summary>Remove an unsolved CAPTCHA.  Deprecated!</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Remove(Captcha captcha)
 {
     return this.Remove(captcha.Id);
 }
コード例 #5
0
ファイル: Client.cs プロジェクト: prog-moh/twtboard
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA text, null if not found or not solved yet.</returns>
  */
 public string GetText(Captcha captcha)
 {
     return this.GetCaptcha(captcha).Text;
 }
コード例 #6
0
ファイル: Client.cs プロジェクト: prog-moh/twtboard
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA if exists, null otherwise.</returns>
  */
 public Captcha GetCaptcha(Captcha captcha)
 {
     return this.GetCaptcha(captcha.Id);
 }
コード例 #7
0
 /**
  * <summary>Report an incorrectly solved CAPTCHA.</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Report(Captcha captcha)
 {
     return(this.Report(captcha.Id));
 }
コード例 #8
0
 /**
  * <summary>Remove an unsolved CAPTCHA.  Deprecated!</summary>
  * <param name="captcha">CAPTCHA.</param>
  * <returns>true on success.</returns>
  */
 public bool Remove(Captcha captcha)
 {
     return(this.Remove(captcha.Id));
 }
コード例 #9
0
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA text, null if not found or not solved yet.</returns>
  */
 public string GetText(Captcha captcha)
 {
     return(this.GetCaptcha(captcha).Text);
 }
コード例 #10
0
 /**
  * <param name="captcha">CAPTCHA.</param>
  * <returns>Uploaded CAPTCHA if exists, null otherwise.</returns>
  */
 public Captcha GetCaptcha(Captcha captcha)
 {
     return(this.GetCaptcha(captcha.Id));
 }
コード例 #11
0
ファイル: HttpClient.cs プロジェクト: prog-moh/twtboard
        /**
         * <see cref="M:DeathByCaptcha.Client.Upload(byte[])"/>
         */
        public override Captcha Upload(byte[] img)
        {
            string boundary = BitConverter.ToString(
                (new SHA1CryptoServiceProvider()).ComputeHash(
                    Encoding.ASCII.GetBytes(DateTime.Now.ToString("G"))
                )
            ).Replace("-", String.Empty);

            Hashtable args = this.Credentials;
            args["swid"] = Convert.ToString(Client.SoftwareVendorId);
            string[] rawArgs = new string[args.Count + 2];
            int i = 0;
            foreach (DictionaryEntry e in args) {
                string v = (string)e.Value;
                rawArgs[i++] = String.Join("\r\n", new string[] {
                    "--" + boundary,
                    "Content-Disposition: form-data; name=\"" + (string)e.Key + "\"",
                    "Content-Length: " + v.Length,
                    "",
                    v
                });
            }
            rawArgs[i++] = String.Join("\r\n", new string[] {
                "--" + boundary,
                "Content-Disposition: form-data; name=\"captchafile\"; filename=\"captcha.jpeg\"",
                "Content-Type: application/octet-stream",
                "Content-Length: " + img.Length,
                ""
            });

            byte[] hdr = Encoding.ASCII.GetBytes(String.Join("\r\n", rawArgs));
            byte[] ftr = Encoding.ASCII.GetBytes("\r\n--" + boundary + "--\r\n");
            byte[] body = new byte[hdr.Length + img.Length + ftr.Length];
            hdr.CopyTo(body, 0);
            img.CopyTo(body, hdr.Length);
            ftr.CopyTo(body, hdr.Length + img.Length);

            Captcha c = new Captcha(this.Call(
                "captcha",
                body,
                "multipart/form-data; boundary=" + boundary
            ));
            return c.Uploaded ? c : null;
        }
コード例 #12
0
ファイル: SocketClient.cs プロジェクト: prog-moh/twtboard
 /**
  * <see cref="M:DeathByCaptcha.Client.Upload(byte[])"/>
  */
 public override Captcha Upload(byte[] img)
 {
     Hashtable args = this.Credentials;
     args["swid"] = Client.SoftwareVendorId;
     args["captcha"] = Convert.ToBase64String(img);
     Captcha c = new Captcha(this.Call("upload", args));
     return c.Uploaded ? c : null;
 }