Http post to ocr space API

Hi, I’m trying to make an HTTP request from a Ionic app to to ocr.space API.

this is the code I wrote, the base64image comes from the Camera plugin and is correctly formatted:

let base64Image = 'data:image/jpeg;base64,' + imageData;

     let data = "base64Image=" + base64Image;

     this.http.post("https://api.ocr.space/parse/image",data,{
       headers: new HttpHeaders().set('Content-Type','application/x-www-form-urlencoded')
                                 .set('apikey',this.APIKEY),
     })
                .subscribe((res)=> console.log(res))

However the response I’m getting is that the format of the image is not correct (not true). What am I doing wrong? Thanks for the help!

Does the request that is sent actually contain correct data?

Thanks a lot for the reply. Sorry for the banal question: how do I check the correctness of the data I send? I can say for sure that the base64image string is correctly formatted

Did you remote debug the problem on the device already?
Follow these instructions here to debug the problem in Safari dev tools:
https://ionic.zone/debug/remote-debug-your-app#ios
Follow these instructions here to debug the problem in Chrome dev tools:
https://ionic.zone/debug/remote-debug-your-app#android
Look at the console and network tab.

Thanks a lot. Your help together with some answers on stackoverflow helped me solve the problem. Everyone who might need this, can find the solution on https://stackoverflow.com/questions/47484744/sending-http-post-to-ocr-space-api/47490215#47490215

1 Like

Awesome.

Is the OCR API any good?

1 Like

I think I need more testing to be sure, but I’m very happy with it’s performance right now!