using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class RecaptchaImageExample
{
private static readonly HttpClient client = new HttpClient();
private const string ApiUrl = "/api/token/recaptcha";
private const string StatusUrl = "/api/token/status";
private const string ApiKey = "YOUR_API_KEY";
public static async Task SolveRecaptchaImage(string websiteUrl, string sitekey)
{
// Prepare request
client.DefaultRequestHeaders.Add("x-api-key", ApiKey);
var payload = new
{
websiteUrl = websiteUrl,
sitekey = sitekey
};
var content = new StringContent(
JsonConvert.SerializeObject(payload),
Encoding.UTF8,
"application/json"
);
// Send request
var response = await client.PostAsync(ApiUrl, content);
var responseString = await response.Content.ReadAsStringAsync();
// Parse response
dynamic result = JsonConvert.DeserializeObject(responseString);
if (!result.isSuccess)
{
throw new Exception($"Error: {result.errorMessage}");
}
string jobGuid = result.jobGuid;
// Poll for status
while (true)
{
var statusResponse = await client.GetAsync($"{StatusUrl}?jobGuid={jobGuid}");
var statusString = await statusResponse.Content.ReadAsStringAsync();
dynamic statusResult = JsonConvert.DeserializeObject(statusString);
if (!statusResult.isSuccess)
{
throw new Exception($"Error: {statusResult.errorMessage}");
}
if (statusResult.data.status == "Completed")
{
return statusResult.data.token;
}
await Task.Delay(5000); // Wait 5 seconds before polling again
}
}
}
import requests
import json
import time
API_URL = "/api/token/recaptcha"
STATUS_URL = "/api/token/status"
API_KEY = "YOUR_API_KEY"
def solve_recaptcha_image(website_url, sitekey):
# Prepare headers and payload
headers = {
"Content-Type": "application/json",
"x-api-key": API_KEY
}
payload = {
"websiteUrl": website_url,
"sitekey": sitekey
}
# Make request
response = requests.post(API_URL, headers=headers, json=payload)
result = response.json()
if not result["isSuccess"]:
raise Exception(f"Error: {result['errorMessage']}")
job_guid = result["jobGuid"]
# Poll for status
while True:
status_response = requests.get(f"{STATUS_URL}?jobGuid={job_guid}", headers={"x-api-key": API_KEY})
status_result = status_response.json()
if not status_result["isSuccess"]:
raise Exception(f"Error: {status_result['errorMessage']}")
if status_result["data"]["status"] == "Completed":
return status_result["data"]["token"]
time.sleep(5) # Wait 5 seconds before polling again
# Example usage
try:
website_url = "https://www.google.com/recaptcha/api2/demo"
sitekey = "6Le-wvkSAAAAAPBMRTvw0Q4Muexq9bi0DJwx_mJ-"
token = solve_recaptcha_image(website_url, sitekey)
print(f"reCAPTCHA solved: {token}")
except Exception as e:
print(str(e))
// reCAPTCHA Image Solving Example
async function solveRecaptchaImage(websiteUrl, sitekey) {
const API_URL = "/api/token/recaptcha";
const STATUS_URL = "/api/token/status";
const API_KEY = "YOUR_API_KEY";
// Prepare request
const payload = {
websiteUrl: websiteUrl,
sitekey: sitekey
};
// Send request
const response = await fetch(API_URL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'x-api-key': API_KEY
},
body: JSON.stringify(payload)
});
const result = await response.json();
if (!result.isSuccess) {
throw new Error(`Error: ${result.errorMessage}`);
}
const jobGuid = result.jobGuid;
// Poll for status
while (true) {
const statusResponse = await fetch(`${STATUS_URL}?jobGuid=${jobGuid}`, {
headers: {
'x-api-key': API_KEY
}
});
const statusResult = await statusResponse.json();
if (!statusResult.isSuccess) {
throw new Error(`Error: ${statusResult.errorMessage}`);
}
if (statusResult.data.status === 'Completed') {
return statusResult.data.token;
}
await new Promise(resolve => setTimeout(resolve, 5000)); // Wait 5 seconds
}
}
// Example of extracting sitekey from reCAPTCHA
function extractRecaptchaSitekey() {
const recaptchaElement = document.querySelector('[data-sitekey]');
if (recaptchaElement && recaptchaElement.dataset.sitekey) {
return recaptchaElement.dataset.sitekey;
}
throw new Error('No reCAPTCHA sitekey found');
}
// Example usage
async function handleRecaptchaImage() {
try {
const websiteUrl = window.location.href;
const sitekey = extractRecaptchaSitekey();
const token = await solveRecaptchaImage(websiteUrl, sitekey);
console.log(`reCAPTCHA solved: ${token}`);
// Use the solved reCAPTCHA in your form
document.getElementById('g-recaptcha-response').value = token;
} catch (error) {
console.error(error.message);
}
}