API
您可以通过 RESTful API 使用我们的服务。
请求格式
请求必须通过 POST
方法以 JSON
格式发送到 https://www.imagetotext.com/api/ocr
端点。
下面是请求参数的列表。
名称 | 值 |
---|---|
api_key | 您的 API 密钥。登录后可在您的个人资料页面上找到。 |
api_secret | 您的 API 密钥。登录后可在您的个人资料页面上找到。 |
image | Base64 编码的图像 |
响应格式
响应将包含状态码为 200
的识别结果的纯文本
HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8
Content-Length: 6
Vary: Accept-Encoding
Date: Wed, 23 Oct 2024 18:32:09 GMT
Connection: close
Hello
或在其他情况下包含状态码为 40*
的错误消息。
HTTP/1.1 404 Not Found
Content-Type: text/html; charset=utf-8
Content-Length: 13
Vary: Accept-Encoding
Date: Wed, 23 Oct 2024 18:29:55 GMT
Connection: close
No text found
示例
Curl 示例
curl -X "POST" "https://www.imagetotext.com/api/ocr" \ -H 'Content-Type: application/json; charset=utf-8' \ -d $'{ "api_key": "API_KEY", "api_secret": "API_SECRET", "image": "iVBORw0KGgoAAAANSUhEUgAAAGQAAAAeCAYAAADaW7vzAAAACXBIWXMAAAsTAAALEwEAmpwYAAACfUlEQVR4nO2Yz0sqURTHlYxSMzBcuJaWLiRFhMRAXYi5kUAQBGnTMlAEfyAUiNBGSHAh6EJBEDXEtQqFqJvCTf9CMNs2lUj5fdyBJ/iUpy6Gd994P3DBO5c5dzifcc6ZkYBBFZJ/fQGMeZgQymBCKIMJoQwmhDKYEMpgQv5nIdVqFcVicekax3G4u7vD6+vr2vGGwyHu7+9n82w2i8FggG1mIyF2ux16vX7p2vPzMyQSCcrl8trx0uk0jo6OZnONRoNUKoVthgnZNiHkEXR7e4ubmxv0er2NhPz8/KBer+P6+hrJZBLdbhdiR1Ah4XAYUqkUVqsVFosFMpkMwWCQT/QqIZPJBC6XC3K5HG63Gx6PB3t7ewgEAvj+/oZY2VjIwcEBnE7nwjCbzXNCWq0WP280GrPzyR1OjtVqtZVCMpkML5AU/t88PT3xgguFAsTKxkJIAq+urhaG1+udE+Lz+WAymRZiGAwGXF5erhRyenrK/yv+xGg0Lj0uFgR7ZJHEK5VK6HS6uaFQKHB+fr5SiFarRSKRWNjn4uJiqWixIJiQk5MTvnZ0Op2F8fLyspaQWCy2sI/D4ZgJFSOCCfH7/Tg+Pp4VcAL5HYlE0Gw2Vwqx2Ww4Ozub2+Pz8xMqlQrxeBxiRTAhpICTAkza3fF4zCeTJHJ3dxej0WilkFKpxMfL5XJ8x0VihEIh7O/v4+3tDWJF0LY3n8/zdYRIIB3T4eEhKpXKbP1vQqbTKaLRKHZ2dvh2l4hQq9V4eHiAmBH84+L7+zseHx/5F8SPj4+Nz+c4Du12G/1+H19fXxA77GsvZTAhlMGEUAYTQhlMCGUwIZTBhFAGE0IZTAjo4heZTxFod+qzwwAAAABJRU5ErkJggg==" }'
使用 Axios 的 JavaScript 示例
axios({ 'method': 'POST', 'url': 'https://www.imagetotext.com/api/ocr', 'headers': { 'Content-Type': 'application/json; charset=utf-8', }, 'data': { 'api_key': 'API_KEY', 'api_secret': 'API_SECRET', 'image': 'iVBORw0KGgoAAAANSUhEUgAAAGQAAAAeCAYAAADaW7vzAAAACXBIWXMAAAsTAAALEwEAmpwYAAACfUlEQVR4nO2Yz0sqURTHlYxSMzBcuJaWLiRFhMRAXYi5kUAQBGnTMlAEfyAUiNBGSHAh6EJBEDXEtQqFqJvCTf9CMNs2lUj5fdyBJ/iUpy6Gd994P3DBO5c5dzifcc6ZkYBBFZJ/fQGMeZgQymBCKIMJoQwmhDKYEMpgQv5nIdVqFcVicekax3G4u7vD6+vr2vGGwyHu7+9n82w2i8FggG1mIyF2ux16vX7p2vPzMyQSCcrl8trx0uk0jo6OZnONRoNUKoVthgnZNiHkEXR7e4ubmxv0er2NhPz8/KBer+P6+hrJZBLdbhdiR1Ah4XAYUqkUVqsVFosFMpkMwWCQT/QqIZPJBC6XC3K5HG63Gx6PB3t7ewgEAvj+/oZY2VjIwcEBnE7nwjCbzXNCWq0WP280GrPzyR1OjtVqtZVCMpkML5AU/t88PT3xgguFAsTKxkJIAq+urhaG1+udE+Lz+WAymRZiGAwGXF5erhRyenrK/yv+xGg0Lj0uFgR7ZJHEK5VK6HS6uaFQKHB+fr5SiFarRSKRWNjn4uJiqWixIJiQk5MTvnZ0Op2F8fLyspaQWCy2sI/D4ZgJFSOCCfH7/Tg+Pp4VcAL5HYlE0Gw2Vwqx2Ww4Ozub2+Pz8xMqlQrxeBxiRTAhpICTAkza3fF4zCeTJHJ3dxej0WilkFKpxMfL5XJ8x0VihEIh7O/v4+3tDWJF0LY3n8/zdYRIIB3T4eEhKpXKbP1vQqbTKaLRKHZ2dvh2l4hQq9V4eHiAmBH84+L7+zseHx/5F8SPj4+Nz+c4Du12G/1+H19fXxA77GsvZTAhlMGEUAYTQhlMCGUwIZTBhFAGE0IZTAjo4heZTxFod+qzwwAAAABJRU5ErkJggg==' } });
PHP 示例
use GuzzleHttp\Client; use GuzzleHttp\Psr7\Request; $client = new Client(); $data = [ 'api_key' => 'API_KEY', 'api_secret' => 'API_SECRET', 'image' => 'iVBORw0KGgoAAAANSUhEUgAAAGQAAAAeCAYAAADaW7vzAAAACXBIWXMAAAsTAAALEwEAmpwYAAACfUlEQVR4nO2Yz0sqURTHlYxSMzBcuJaWLiRFhMRAXYi5kUAQBGnTMlAEfyAUiNBGSHAh6EJBEDXEtQqFqJvCTf9CMNs2lUj5fdyBJ/iUpy6Gd994P3DBO5c5dzifcc6ZkYBBFZJ/fQGMeZgQymBCKIMJoQwmhDKYEMpgQv5nIdVqFcVicekax3G4u7vD6+vr2vGGwyHu7+9n82w2i8FggG1mIyF2ux16vX7p2vPzMyQSCcrl8trx0uk0jo6OZnONRoNUKoVthgnZNiHkEXR7e4ubmxv0er2NhPz8/KBer+P6+hrJZBLdbhdiR1Ah4XAYUqkUVqsVFosFMpkMwWCQT/QqIZPJBC6XC3K5HG63Gx6PB3t7ewgEAvj+/oZY2VjIwcEBnE7nwjCbzXNCWq0WP280GrPzyR1OjtVqtZVCMpkML5AU/t88PT3xgguFAsTKxkJIAq+urhaG1+udE+Lz+WAymRZiGAwGXF5erhRyenrK/yv+xGg0Lj0uFgR7ZJHEK5VK6HS6uaFQKHB+fr5SiFarRSKRWNjn4uJiqWixIJiQk5MTvnZ0Op2F8fLyspaQWCy2sI/D4ZgJFSOCCfH7/Tg+Pp4VcAL5HYlE0Gw2Vwqx2Ww4Ozub2+Pz8xMqlQrxeBxiRTAhpICTAkza3fF4zCeTJHJ3dxej0WilkFKpxMfL5XJ8x0VihEIh7O/v4+3tDWJF0LY3n8/zdYRIIB3T4eEhKpXKbP1vQqbTKaLRKHZ2dvh2l4hQq9V4eHiAmBH84+L7+zseHx/5F8SPj4+Nz+c4Du12G/1+H19fXxA77GsvZTAhlMGEUAYTQhlMCGUwIZTBhFAGE0IZTAjo4heZTxFod+qzwwAAAABJRU5ErkJggg==' ]; $request = new Request('POST', 'https://www.imagetotext.com/api/ocr', [ 'Content-Type' => 'application/json; charset=utf-8', ], json_encode($data) ); try { $response = $client->send($request); echo sprintf('Response HTTP: %d', $response->getStatusCode()); } catch (\Exception $e) { echo sprintf('Error: %s', $e->getMessage()); }