Calling Method
Request Format
POST Request
Note: The Content-Type must be application/x-www-form-urlencoded
, and the request body should be formatted using urlencode
.
Request Restrictions
The request image must be base64-encoded and then passed in after urlencode
: Base64 encoding of an image means converting image data into a string, using this string instead of an image URL. You can first obtain the binary data of the image, remove the encoding header, and then apply urlencode
.
Note:
- The base64 encoding of the image does not include the image header, such as (data:image/jpg;base64,).
- When using tools like Postman or request libraries in Python, PHP, etc.,
urlencode
is automatically handled, so manual processing is not required. - Supported image formats: PNG, JPG, JPEG, BMP, TIFF. If other formats are needed, please contact technical support.
Request URL Data Format
To send a POST request to the API service address, parameters must be included in the URL:
access_token
: Required parameter, refer to "Access Token Retrieval."
Note: The access_token
is valid for 30 days and must be refreshed every 30 days.
Parameters in the POST request should be structured according to the API documentation.
For example, when calling the Text Recognition API, use an HTTPS POST request:
https://openapi.ocr.sys303.com/api/v1/ocr/general?access_token=24.f9ba9c5241b67688bb4adbed8bc91dec.2592000.1485570332.282335-8574074
Request Example
- bash
- python
- C#
- Java
curl --request POST \
--url 'https://openapi.ocr.sys303.com/api/v1/ocr/general?access_token=【access_token】' \
--header 'content-type: multipart/form-data' \
--form 'image=【image path】' --form language_type=0
# encoding:utf-8
import requests
import base64
def main():
request_url = 'https://openapi.ocr.sys303.com/api/v1/ocr/general'
access_token= '【access_token】'
f = open('【image path】', 'rb')
img = base64.b64encode(f.read())
params = {"image": img}
request_url = request_url + "?access_token=" + access_token
headers = {'content-type': 'application/x-www-form-urlencoded'}
response = requests.post(request_url, data=params, headers=headers)
if response:
print (response.json())
if __name__ == '__main__':
main()
using System;
using System.IO;
using System.Net;
using System.Text;
public class AccurateBasic
{
public static string RunAccurateBasic()
{
string requestUrl = "https://openapi.ocr.sys303.com/api/v1/ocr/general";
string accessToken = "【access_token】";
string imagePath = "【image path】";
string fullUrl = requestUrl + "?access_token=" + accessToken;
string base64Image = GetFileBase64(imagePath);
string postData = "image=" + Uri.EscapeDataString(base64Image);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(fullUrl);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
byte[] data = Encoding.UTF8.GetBytes(postData);
request.ContentLength = data.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(data, 0, data.Length);
}
try
{
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
{
string result = reader.ReadToEnd();
Console.WriteLine(result);
return result;
}
}
catch (WebException ex)
{
using (StreamReader reader = new StreamReader(ex.Response.GetResponseStream()))
{
string errorResponse = reader.ReadToEnd();
Console.WriteLine("Error Response:");
Console.WriteLine(errorResponse);
}
throw;
}
}
public static string GetFileBase64(string filePath)
{
byte[] fileBytes = File.ReadAllBytes(filePath);
return Convert.ToBase64String(fileBytes);
}
public static void Main(string[] args)
{
RunAccurateBasic();
}
}
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Base64;
public class RunAccurateBasic {
public static void main(String[] args) {
String requestUrl = "https://openapi.ocr.sys303.com/api/v1/ocr/general";
String accessToken = "【access_token】";
String imagePath = "【image path】";
try {
String result = runAccurateBasic(requestUrl, accessToken, imagePath);
System.out.println("OCR Result: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static String runAccurateBasic(String requestUrl, String accessToken, String imagePath) throws Exception {
String imageBase64 = encodeFileToBase64(imagePath);
String fullUrl = requestUrl + "?access_token=" + accessToken;
URL url = new URL(fullUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
String params = "image=" + URLEncoder.encode(imageBase64, "UTF-8");
try (OutputStream outputStream = connection.getOutputStream()) {
outputStream.write(params.getBytes("UTF-8"));
}
int responseCode = connection.getResponseCode();
if (responseCode == 200) {
StringBuilder response = new StringBuilder();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getInputStream(), "UTF-8"))) {
String line;
while ((line = reader.readLine()) != null) {
response.append(line);
}
}
return response.toString();
} else {
StringBuilder errorResponse = new StringBuilder();
try (BufferedReader reader = new BufferedReader(
new InputStreamReader(connection.getErrorStream(), "UTF-8"))) {
String line;
while ((line = reader.readLine()) != null) {
errorResponse.append(line);
}
}
throw new Exception("Error Response: " + errorResponse.toString());
}
}
public static String encodeFileToBase64(String filePath) throws IOException {
File file = new File(filePath);
try (FileInputStream fis = new FileInputStream(file)) {
byte[] fileBytes = new byte[(int) file.length()];
fis.read(fileBytes);
return Base64.getEncoder().encodeToString(fileBytes);
}
}
}
Response Format
JSON Format
Refer to the corresponding API for the specific format.