要使用OCRKing API,首先需要注册一个账户并获得API密钥。然后,按照以下步骤使用Java进行API调用:
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpPost; import org.apache.http.entity.mime.MultipartEntityBuilder; import org.apache.http.entity.mime.content.FileBody; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; HttpClient httpClient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost("http://api.ocrking.com/ok.html"); MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create(); entityBuilder.addPart("file", new FileBody(new File("path/to/your/image.jpg"))); httpPost.setEntity(entityBuilder.build()); HttpResponse response = httpClient.execute(httpPost); HttpEntity responseEntity = response.getEntity(); String responseString = EntityUtils.toString(responseEntity); ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readTree(responseString); String result = jsonNode.get("result").asText(); 以上就是使用Java调用OCRKing API的基本步骤。根据OCRKing API的具体文档和需求,可能还需要设置其他请求参数和处理其他响应字段。