Search code examples
c#2captcha

C# 2captcha image post with Base64


C# 2captcha image post

         HttpClient client = new HttpClient();
         var bytes = File.ReadAllBytes("sample.jpg");

         var base64 =   Convert.ToBase64String(bytes);

         var secretKey = "8ffa...";
         var url = "https://2captcha.com/in.php?key=" + secretKey;

         using ( client = new HttpClient())
         {
             var content = new StringContent(base64);

             var response = await client.PostAsync(url , content);

             var stringResponse = await response.Content.ReadAsStringAsync();

             Console.WriteLine(stringResponse);
             Console.ReadLine();

My every response is ERROR_ZERO_CAPTCHA_FILESIZE and i don't know what's the problem.


Solution

  • ERROR_ZERO_CAPTCHA_FILESIZE means that image size is less than 100 bytes (NOT kilobytes). You need to check thoroughly if you're sending image correctly. Here is the sample of a proper Base64 sample form:

    <form method="post" action="https://2captcha.com/in.php">
    <input type="hidden" name="method" value="base64">
    <input type="text" name="key" value="YOUR_APIKEY">
    <textarea name="body">BASE64_FILE</textarea>
    <input type="submit" value="Upload and get the ID">
    </form>
    

    Maybe the problem is in your sample.jpg file. Try to encode to base64 a real captcha picture (you can take one on the 2captcha sign-in page actually). Your base64 text string must have a weight of an image file, so it must be at least a few kilobytes.