ProductsIntegrationsResourcesDocumentationPricing
Start Now

© 2026 CapSolver. All rights reserved.

CONTACT US

Slack: lola@capsolver.com

Products

  • reCAPTCHA v2
  • reCAPTCHA v3
  • Cloudflare Turnstile
  • Cloudflare Challenge
  • AWS WAF
  • Browser Extension
  • Many more CAPTCHA types

Integrations

  • Selenium
  • Playwright
  • Puppeteer
  • n8n
  • Partners
  • View All Integrations

Resources

  • Referral System
  • Documentation
  • API Reference
  • Blog
  • FAQs
  • Glossary
  • Status

Legal

  • Terms & Conditions
  • Privacy Policy
  • Refund Policy
  • Don't Sell My Info
Blog/reCAPTCHA/Solving reCAPTCHA in C++: A Complete Guide
Jul30, 2024

Solving reCAPTCHA in C++: A Complete Guide

Ethan Collins

Ethan Collins

Pattern Recognition Specialist

TL;DR

This guide explains how to solve Google reCAPTCHA challenges using C++ by integrating with the CapSolver API. It walks through setting up a C++ project with cpr and jsoncpp, creating a reCAPTCHA task, polling for the task result, and retrieving the final reCAPTCHA token. The approach is suitable for performance-critical or legacy C++ environments that require programmatic CAPTCHA handling.

Introduction

reCAPTCHA is a widely used CAPTCHA service developed by Google to protect websites from bots and automated abuse. It works by presenting users with challenges that are easy for humans to solve but difficult for automated systems. These challenges can include identifying objects in images, solving puzzles, or clicking checkboxes.

The primary goal of reCAPTCHA is to ensure that interactions on websites are performed by real people, not automated scripts or bots. It serves as a gatekeeper to prevent automated submissions and interactions, which can be detrimental to both security and user experience.

Why Solve reCAPTCHA with C++?

C++ is a powerful programming language known for its performance and efficiency. It is commonly used in scenarios where speed and resource management are critical, such as in game development, high-performance computing, and system-level programming. Here are some reasons why solving reCAPTCHA with C++ might be preferred:

  1. Performance: C++ offers fine-grained control over system resources and can execute tasks with minimal overhead, making it suitable for scenarios requiring high performance and speed.

  2. Integration with Existing Systems: Many legacy systems and applications are built using C++. If you are working within such an environment, using C++ to solve reCAPTCHA might be a natural choice for maintaining consistency.

  3. Low-Level Control: C++ provides low-level control over hardware and system resources, which can be advantageous for creating highly optimized solutions.

  4. Compatibility: C++ can interface with various APIs and libraries, making it possible to integrate third-party services like CapSolver for CAPTCHA solving.

Guide Overview

In this guide, we'll explore how to solve reCAPTCHA using C++ by interacting with the CapSolver API. This process involves creating a task for the reCAPTCHA challenge and then retrieving the result of that task. We'll utilize the cpr library for making HTTP requests and the jsoncpp library for parsing JSON data.

By following this tutorial, you'll learn how to:

  1. Set up a C++ project with the required libraries.
  2. Create a task to solve a reCAPTCHA challenge.
  3. Retrieve the result of the task and use it in your application.

Whether you're integrating reCAPTCHA solving into an existing C++ application or developing a new tool, this guide will provide you with the knowledge and code needed to achieve your goals efficiently.

Solving reCAPTCHA in C++

reCAPTCHA is a popular tool used by websites to prevent bots from engaging in abusive activities. However, for legitimate use cases, developers might need to bypass these challenges programmatically. In this guide, we'll walk through solving reCAPTCHA using C++ by interacting with the CapSolver API. This involves creating a task for the reCAPTCHA and then retrieving the task result. We'll use the cpr library for HTTP requests and jsoncpp for JSON parsing. Let's dive in!

Prerequisites

Before we start, ensure you have the following libraries installed:

  1. cpr: A C++ HTTP library.
  2. jsoncpp: A C++ library for JSON parsing.

You can install these using vcpkg:

bash Copy
vcpkg install cpr jsoncpp

Step 1: Setting Up Your Project

Create a new C++ project and include the necessary headers for cpr and jsoncpp.

cpp Copy
#include <iostream>
#include <cpr/cpr.h>
#include <json/json.h>

Step 2: Define Functions for Creating and Getting Task Results

We'll define two main functions: createTask and getTaskResult.

  1. createTask: This function creates a reCAPTCHA task.
  2. getTaskResult: This function retrieves the result of the created task.

Here's the complete code:

cpp Copy
#include <iostream>
#include <cpr/cpr.h>
#include <json/json.h>

std::string createTask(const std::string& apiKey, const std::string& websiteURL, const std::string& websiteKey) {
    Json::Value requestBody;
    requestBody["clientKey"] = apiKey;
    requestBody["task"]["type"] = "ReCaptchaV2Task";
    requestBody["task"]["websiteURL"] = websiteURL;
    requestBody["task"]["websiteKey"] = websiteKey;

    Json::StreamWriterBuilder writer;
    std::string requestBodyStr = Json::writeString(writer, requestBody);

    cpr::Response response = cpr::Post(
        cpr::Url{"https://api.capsolver.com/createTask"},
        cpr::Body{requestBodyStr},
        cpr::Header{{"Content-Type", "application/json"}}
    );

    Json::CharReaderBuilder reader;
    Json::Value responseBody;
    std::string errs;
    std::istringstream s(response.text);
    std::string taskId;

    if (Json::parseFromStream(reader, s, &responseBody, &errs)) {
        if (responseBody["errorId"].asInt() == 0) {
            taskId = responseBody["taskId"].asString();
        } else {
            std::cerr << "Error: " << responseBody["errorCode"].asString() << std::endl;
        }
    } else {
        std::cerr << "Failed to parse response: " << errs << std::endl;
    }

    return taskId;
}

std::string getTaskResult(const std::string& apiKey, const std::string& taskId) {
    Json::Value requestBody;
    requestBody["clientKey"] = apiKey;
    requestBody["taskId"] = taskId;

    Json::StreamWriterBuilder writer;
    std::string requestBodyStr = Json::writeString(writer, requestBody);

    while (true) {
        cpr::Response response = cpr::Post(
            cpr::Url{"https://api.capsolver.com/getTaskResult"},
            cpr::Body{requestBodyStr},
            cpr::Header{{"Content-Type", "application/json"}}
        );

        Json::CharReaderBuilder reader;
        Json::Value responseBody;
        std::string errs;
        std::istringstream s(response.text);

        if (Json::parseFromStream(reader, s, &responseBody, &errs)) {
            if (responseBody["status"].asString() == "ready") {
                return responseBody["solution"]["gRecaptchaResponse"].asString();
            } else if (responseBody["status"].asString() == "processing") {
                std::cout << "Task is still processing, waiting for 5 seconds..." << std::endl;
                std::this_thread::sleep_for(std::chrono::seconds(5));
            } else {
                std::cerr << "Error: " << responseBody["errorCode"].asString() << std::endl;
                break;
            }
        } else {
            std::cerr << "Failed to parse response: " << errs << std::endl;
            break;
        }
    }

    return "";
}

int main() {
    std::string apiKey = "YOUR_API_KEY";
    std::string websiteURL = "https://example.com";
    std::string websiteKey = "SITE_KEY";

    std::string taskId = createTask(apiKey, websiteURL, websiteKey);
    if (!taskId.empty()) {
        std::cout << "Task created successfully. Task ID: " << taskId << std::endl;
        std::string recaptchaResponse = getTaskResult(apiKey, taskId);
        std::cout << "reCAPTCHA Response: " << recaptchaResponse << std::endl;
    } else {
        std::cerr << "Failed to create task." << std::endl;
    }

    return 0;
}

Explanation

  1. createTask Function: This function constructs a JSON request body with the necessary parameters (apiKey, websiteURL, websiteKey) and sends it to the CapSolver API to create a reCAPTCHA task. It parses the response to retrieve the taskId.

  2. getTaskResult Function: This function repeatedly checks the status of the created task using the taskId until the task is complete. Once complete, it retrieves and returns the reCAPTCHA response.

  3. main Function: The main function initializes the necessary variables (apiKey, websiteURL, websiteKey), calls createTask to get a taskId, and then calls getTaskResult to get the reCAPTCHA solution.

Conclusion

This guide demonstrated how to solve reCAPTCHA in C++ using the CapSolver API. By following the steps above, you can integrate reCAPTCHA solving into your C++ applications. Ensure you handle API keys and other sensitive information securely in your actual implementation.

Feel free to customize and expand the code to suit your specific requirements. Happy coding!


FAQs

1. Is it legal to solve reCAPTCHA programmatically using C++?

Solving reCAPTCHA programmatically may violate the terms of service of Google reCAPTCHA and the target website. This approach should only be used for legitimate purposes, such as testing, automation on sites you own, or scenarios where you have explicit authorization. Always review and comply with applicable laws, website policies, and service agreements.

2. Which reCAPTCHA versions does this C++ example support?

The example shown uses ReCaptchaV2Task, which is designed for reCAPTCHA v2 challenges. CapSolver also supports other variants (such as reCAPTCHA v3 or enterprise versions), but those require different task types and parameters. You should consult the CapSolver documentation and adjust the task configuration accordingly.

3. Why use C++ instead of Python or JavaScript for reCAPTCHA solving?

C++ is often chosen for its high performance, low-level control, and ease of integration with existing native applications or legacy systems. If your application is already written in C++ or has strict performance and resource constraints, implementing reCAPTCHA solving directly in C++ can be more efficient than introducing an additional runtime or service layer.

More

reCAPTCHAApr 16, 2026

reCAPTCHA Score Explained: Range, Meaning, and How to Improve It

Understand reCAPTCHA v3 score range (0.0 to 1.0), its meaning, and how to improve your score. Learn how to handle low scores and optimize user experience.

Rajinder Singh
Rajinder Singh
reCAPTCHAApr 16, 2026

reCAPTCHA Invalid Site Key or Token? Causes & Fix Guide

Facing "reCAPTCHA Invalid Site Key" or "invalid reCAPTCHA token" errors? Discover common causes, step-by-step fixes, and troubleshooting tips to resolve reCAPTCHA verification failed issues. Learn how to fix reCAPTCHA verification failed please try again.

Contents

Aloísio Vítor
Aloísio Vítor
reCAPTCHAApr 15, 2026

reCAPTCHA Verification Failed? How to Fix "Please Try Again" Errors

Fix reCAPTCHA verification failed errors fast. Step-by-step manual fixes for users and a Python API guide for developers using CapSolver. Covers v2, v3, and Enterprise.

Adélia Cruz
Adélia Cruz
reCAPTCHAApr 15, 2026

reCAPTCHA v2 vs v3: Key Differences Every Developer Should Know

Understand the difference between reCAPTCHA v2 and v3 — how each works, when to use them, and how automated workflows handle both. A clear, technical comparison for developers.

Nikolai Smirnov
Nikolai Smirnov