"No file uploaded or URL provided" when calling ocr.space API文件上載到ocr.space API
我想知道我們如何可以上傳文件到服務器在上面的URL發送,該代碼是C#,但我想它在Java中的Android
其中我的代碼是
`final HttpClient httpclient = new DefaultHttpClient();
final HttpPost httppost = new HttpPost("https://api.ocr.space/parse/image");
//httppost.addHeader("User-Agent", "Mozilla/5.0");
//httppost.addHeader("Accept-Language", "en-US,en;q=0.5");
//con.setRequestMethod("POST");
// con.setRequestProperty("User-Agent", "Mozilla/5.0");
// con.setRequestProperty("Accept-Language", "en-US,en;q=0.5");
final FileBody image = new FileBody(new File(fileName));
final MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("isOverlayRequired", new StringBody(Boolean.toString(isOverlayRequired)));
reqEntity.addPart("language", new StringBody(langCode));
reqEntity.addPart("apikey", new StringBody(apiKey));
reqEntity.addPart("file",image);
httppost.setEntity(reqEntity);
final HttpResponse response = httpclient.execute(httppost);
final HttpEntity resEntity = response.getEntity();
final StringBuilder sb = new StringBuilder();
if (resEntity != null) {
final InputStream stream = resEntity.getContent();
byte bytes[] = new byte[4096];
int numBytes;
while ((numBytes=stream.read(bytes))!=-1) {
if (numBytes!=0) {
sb.append(new String(bytes, 0, numBytes));
}
}
}
Log.i("data", sb.toString());`
但它提供了異常,因爲
javax.net.ssl.SSLException: hostname in certificate didn't match: <api.ocr.space> != <ocr.a9t9.com> OR <ocr.a9t9.com> OR <www.ocr.a9t9.com>
嘿男人!你有沒有解決這個問題?你能提供解決方案嗎! – Yekatandilburg