first of all, the address of the reference document is here.
https://cloud.tencent.com/doc.
is described in detail below.
I want to learn to call Tencent Cloud"s open OCR interface. After finding a lot of data, after solving the 401 error for the first time, the compiler does not report an error, but now I stop at the 400th error returned and do not know how to solve the problem. Please check it and give me your advice. thank you.
I"ve been looking for it for several times, but I can"t find out why I reported 400. Please take a look at it in your spare time. Thank you. -sharp-sharp-sharp problem description
the environmental background of the problems and what methods you have tried
The tool used byis that IDEA2017, tried to get rid of head and add its own head. The following request code has been tried, but the returned data is empty. That is, response is null,. Even toString will report a null pointer.
Response response = given().contentType("application/json")
.header("host", "recognition.image.myqcloud.com")
.header("authorization", authorization)
.body(body) //bodybody
.post("http://recognition.image.myqcloud.com/ocr/general");
related codes
/ / Please paste the code text below (do not replace the code with pictures)
main function code:
public static void main(String arg[]) throws Exception {
String appId = "id";
String secretKey = "key";
String secretId = "id";
String bucketName = "";
Long expired = 259200L;
//
String authorization = Sign.appSign(appId, secretId, secretKey, bucketName, expired);
//base64base64
String imageCode = GetImageStr(new File("C:\\Users\\William\\Desktop\\\\bandicam 2018-08-14 17-58-15-348.mp4_20180814_180014.334.jpg").getAbsolutePath());
//JSON:{"appid":"","url":null,"image":"/9j/4AAQSkZJR..."}
JsonOcr jsonOcr = new JsonOcr();
jsonOcr.setAppid(appId);
jsonOcr.setImage(imageCode);
ObjectMapper mapper = new ObjectMapper();
String body = mapper.writeValueAsString(jsonOcr);
//POSTUrl,JSON
String url = "http://recognition.image.myqcloud.com/ocr/general";
HttpResponse response = HttpUtil.**doExecuteOCR**(url, HttpUtil.Method.POST, body, authorization);
System.out.println(response.toString());
}
the request code is as follows:
public static HttpResponse doExecuteOCR(String url, Method method, String content,String authorization) throws IOException, NullPointerException {
RequestConfig defaultRequestConfig = RequestConfig.custom()
.setSocketTimeout(2 * 60 * 1000)
.setConnectTimeout(2 * 60 * 1000)
.setConnectionRequestTimeout(2 * 60 * 1000)
.setStaleConnectionCheckEnabled(true)
.build();
CloseableHttpClient client = HttpClients.custom()
.setDefaultRequestConfig(defaultRequestConfig)
.build();
//
HttpEntity entity = new StringEntity(content, ContentType.APPLICATION_JSON);
//
HttpRequestBase request = **buildRequestOcr**(url, method, entity,authorization);
return client.execute(request);
}
the creation request code is as follows:
private static HttpRequestBase buildRequestOcr(String url, final HttpUtil.Method method, HttpEntity entity,String authorization) {
HttpRequestBase request = null;
HttpPost post = new HttpPost(url);
post.setHeader("host","recognition.image.myqcloud.com");
post.setHeader("content-type","application/json");
post.setHeader("authorization",authorization);
post.setEntity(entity);
request = post;
return request;
}
the returned result of Tencent API is output via System.out.println (response.toString ()):
HttpResponseProxy {HTTP/1.1 400 Bad Request [Server: nginx, Date: Thu, 16 Aug 2018 07:44:48 GMT, Content-Type: application/json; charset=utf-8, Content-Length: 86, Connection: keep-alive]}
what result do you expect? What is the error message actually seen?
I hope some great god can tell me what the mistake is.