using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;
public class TextCaptchaExample
{
private static readonly HttpClient client = new HttpClient();
private const string ApiUrl = "/api/captcha";
private const string ApiKey = "YOUR_API_KEY";
public static async Task SolveCaptcha(string base64Image, string providerCode = null)
{
// Prepare request
client.DefaultRequestHeaders.Add("x-api-key", ApiKey);
var payload = new
{
image = base64Image,
providerCode = providerCode
};
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)
{
return result.data.prediction;
}
else
{
throw new Exception($"Error: {result.errorMessage}");
}
}
}
import requests
import json
import base64
API_URL = "/api/captcha"
API_KEY = "YOUR_API_KEY"
def solve_captcha(image_path, provider_code=None):
# Read image and convert to base64
with open(image_path, "rb") as image_file:
encoded_image = base64.b64encode(image_file.read()).decode('utf-8')
# Prepare headers and payload
headers = {
"Content-Type": "application/json",
"x-api-key": API_KEY
}
payload = {
"image": encoded_image
}
if provider_code:
payload["providerCode"] = provider_code
# Make request
response = requests.post(API_URL, headers=headers, json=payload)
result = response.json()
if result["isSuccess"]:
return result["data"]["prediction"]
else:
raise Exception(f"Error: {result['errorMessage']}")
# Example usage
try:
captcha_text = solve_captcha("captcha.png", "XYZ")
print(f"CAPTCHA solved: {captcha_text}")
except Exception as e:
print(str(e))
// CAPTCHA Solving Example
async function solveCaptcha(base64Image, providerCode = null) {
const API_URL = "/api/captcha";
const API_KEY = "YOUR_API_KEY";
// Prepare request
const payload = {
image: base64Image
};
if (providerCode) {
payload.providerCode = providerCode;
}
// 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) {
return result.data.prediction;
} else {
throw new Error(`Error: ${result.errorMessage}`);
}
}
// Example usage
async function handleCaptcha() {
try {
// Get base64 image from your application
const base64Image = 'iVBORw0KGgoAAAANSUhEUgAAAGQAAA...';
const captchaText = await solveCaptcha(base64Image, 'XYZ');
console.log(`CAPTCHA solved: ${captchaText}`);
// Use the solved CAPTCHA in your form
document.getElementById('captcha-input').value = captchaText;
} catch (error) {
console.error(error.message);
}
}