API Request Sample

Sample API

Take the Indian card as example.

https://cloudapi.accuauth.in/ocr/indian_card

1.HTTP Sample

POST /ocr/indian_card HTTP/1.1
Host: cloudapi.accuauth.in
X-DF-API-ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X-DF-API-SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Cache-Control: no-cache
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="idcard3.jpg"
Content-Type: image/jpeg

...
------WebKitFormBoundary7MA4YWxkTrZu0gW--

2.cURL Sample

curl -X POST \
  https://cloudapi.accuauth.in/ocr/indian_card \
  -H 'cache-control: no-cache' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -H 'X-DF-API-ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -H 'X-DF-API-SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' \
  -F file=@idcard3.jpg

3.C Sample

CURL *hnd = curl_easy_init();

curl_easy_setopt(hnd, CURLOPT_CUSTOMREQUEST, "POST");
curl_easy_setopt(hnd, CURLOPT_URL, "https://cloudapi.accuauth.in/ocr/indian_card");

struct curl_slist *headers = NULL;
headers = curl_slist_append(headers, "cache-control: no-cache");
headers = curl_slist_append(headers, "X-DF-API-ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
headers = curl_slist_append(headers, "X-DF-API-SECRET: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");
headers = curl_slist_append(headers, "content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW");
curl_easy_setopt(hnd, CURLOPT_HTTPHEADER, headers);

curl_easy_setopt(hnd, CURLOPT_POSTFIELDS, "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"idcard3.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");

CURLcode ret = curl_easy_perform(hnd);

4.java Sample

import java.io.IOException;
import java.io.File;

import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.MultipartBody;

public class PostExample {
  final MediaType MEDIA_TYPE_JPG = MediaType.parse("image/jpg");
  String post(String file1) throws IOException {
    OkHttpClient client = new OkHttpClient();
    RequestBody body = new MultipartBody.Builder()
                .setType(MultipartBody.FORM)
                .addFormDataPart("file", "1.jpg", RequestBody.create(MEDIA_TYPE_JPG, new File(file1)))
                .build();
    Request request = new Request.Builder()
                                .addHeader("X-DF-API-ID", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                                .addHeader("X-DF-API-SECRET", "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
                                .url("https://cloudapi.accuauth.in/ocr/indian_card")
                                .post(body)
                                .build();
    Response response = client.newCall(request).execute();
    return response.body().string();
  }

  public static void main(String[] args) throws IOException {
    PostExample example = new PostExample();
    String response = example.post("./1.jpg");
    System.out.println(response);
  }
}

5.nodejs Sample

var http = require("https");

var options = {
  "method": "POST",
  "hostname": "cloudapi.accuauth.in",
  "port": null,
  "path": "/ocr/idcard",
  "headers": {
    "content-type": "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
    "X-DF-API-ID": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    "X-DF-API-SECRET": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  }
};

var req = http.request(options, function (res) {
  var chunks = [];

  res.on("data", function (chunk) {
    chunks.push(chunk);
  });

  res.on("end", function () {
    var body = Buffer.concat(chunks);
    console.log(body.toString());
  });
});

req.write("------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"file\"; filename=\"idcard3.jpg\"\r\nContent-Type: image/jpeg\r\n\r\n\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--");
req.end();

6.php Sample

<?php

$request = new HttpRequest();
$request->setUrl('https://cloudapi.accuauth.in/ocr/indian_card');
$request->setMethod(HTTP_METH_POST);

$request->setHeaders(array(
  'X-DF-API-ID' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'X-DF-API-SECRET' => 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
  'content-type' => 'multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
));

$request->setBody('------WebKitFormBoundary7MA4YWxkTrZu0gW
Content-Disposition: form-data; name="file"; filename="idcard3.jpg"
Content-Type: image/jpeg


------WebKitFormBoundary7MA4YWxkTrZu0gW--');

try {
  $response = $request->send();

  echo $response->getBody();
} catch (HttpException $ex) {
  echo $ex;
}

7.ruby Sample

require 'uri'
require 'rest-client'

url = URI("https://cloudapi.accuauth.in/ocr/indian_card")

headers = {
  X-DF-API-ID: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  X-DF-API-SECRET: "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
params = {
  file: File.new(filepath, 'rb'),
  multipart: true
}

response = RestClient::Request.execute method: :post, url: url, payload: params, headers: headers, timeout: timeout

puts response.body

8.python Sample

import requests

url = "https://cloudapi.accuauth.in/ocr/indian_card"

headers = {
    'X-DF-API-ID': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
    'X-DF-API-SECRET': "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
}
files = {'file': open(filepath, 'rb')}
response = requests.post(api_host, headers=headers, files=files)

print(response.text)

results matching ""

    No results matching ""