Cloud OCR SDK Authentication

ABBYY Cloud OCR SDK service requires authentication before allowing access to its API. To have your client program authenticated with the service, you need a registered Application ID and Application Password. You can find the Application ID and Application Password in the e-mail message sent to you on application creation. To get started and create an application, please follow this link to register.

The service uses Basic access authentication for the API calls. The client program should include an authorization header field with each HTTP request it sends to the service: "Authorization: Basic <ApplicationID:ApplicationPassword>". The authorization header contains the authentication scheme (Basic) and the appropriate Application ID and Application Password separated with a colon and Base64-encoded. The service processes the request only if it is sent with a properly formed authorization header that includes a valid Application ID and Application Password.

Note: In contrast, the GET request to download the result (using the URL returned by the getTaskStatus method) should not include any authorization headers. Using your Cloud OCR SDK authorization headers will result in an error.

Different programming languages or development environments can require different steps to add a correct authorization header. Consult our Code Samples for the programming language you use. In case of doubt please use a HTTP debugger such as Fiddler to check that the HTTP request sent to the service by your program actually contains a properly formed authentication header.

The communication security can be provided via Secure Sockets Layer (SSL). The client can request a secure connection from the server, check the trusted certificate authority returned by the server and, if the certificate is valid, begin the secured connection. Using SSL is optional.

C# sample

// Create a Web request using location-based URL and
// setup it with the correct Application ID and Application Password

String url = "http://<PROCESSING_LOCATION_ID>.ocrsdk.com/processImage?Language=English,Russian";
WebRequest request = WebRequest.Create( url );

Encoding encoding = Encoding.GetEncoding("iso-8859-1");
string toEncode = ApplicationID + ":" + ApplicationPassword;
string baseEncoded = Convert.ToBase64String(encoding.GetBytes(toEncode));

request.Headers.Add( "Authorization", "Basic " + baseEncoded );
//The request now has authentication header set up correctly

Have more questions? Submit a request

Comments

1 comment

  • Avatar

    Kainat Khalid

    I'm still getting 401 authorization Error.
    This is the I'm using:

    String url = "https://cloud-westus.ocrsdk.com/processImage?Language=English,Russian";
                WebRequest request = WebRequest.Create(url);
                request.Method = "POST";

                Encoding encoding = Encoding.GetEncoding("iso-8859-1");
                string toEncode = ApplicationID + ":" + ApplicationPassword;
                string baseEncoded = Convert.ToBase64String(encoding.GetBytes(toEncode));

                request.Headers.Add("Authorization", "Basic " + baseEncoded);

                // Read the PDF file into a byte array
                byte[] fileBytes = File.ReadAllBytes(pdfFilePath);

                // Set the request content type and length
                request.ContentType = "application/octet-stream";
                request.ContentLength = fileBytes.Length;

                // Write the file bytes to the request stream
                using (Stream requestStream = request.GetRequestStream())
                {
                    requestStream.Write(fileBytes, 0, fileBytes.Length);
                }

               

                // Send the request and get the response
                using (WebResponse response = await request.GetResponseAsync())
                using (Stream responseStream = response.GetResponseStream())
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    string responseText = await reader.ReadToEndAsync();
                    // Process the response text as needed
                    return responseText;
                }

    0

Please sign in to leave a comment.