0
MS 컴퓨터 비전 APi에 대한 OCR 게시 요청을 보내고 응답을 반환합니다. HTTP/1.1 415 지원되지 않는 미디어 유형 [Cache-Control : no-cache, Pragma : no-cache, Content-Length : 183, Content-Type : application/json;http 응답을 반환하는 컴퓨터 비전 ocr API : Java http 요청에 대해 지원되지 않는 미디어 유형
여기에 내 Java 코드가있어 요청에 multipartfile (jpg)을 추가 한 다음 게시합니다.
HttpClient httpClient = HttpClientBuilder.create().build();
String fileContentType = file.getContentType();
URI uri = buildUri();
if(uri == null){
//throw some exception
}
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", fileContentType);
request.setHeader("Ocp-Apim-Subscription-Key", subscriptionKey);
MultipartEntityBuilder mpEB = MultipartEntityBuilder.create();
InputStream fileInputStream = file.getInputStream();
//modify method to add filename if later need arises
//link: https://memorynotfound.com/apache-httpclient-multipart-upload-request/
mpEB.addBinaryBody("image", fileInputStream);
mpEB.setContentType(ContentType.MULTIPART_FORM_DATA);
HttpEntity image = mpEB.build();
request.setEntity(image);
HttpResponse response = httpClient.execute(request);
HttpEntity entity = response.getEntity();
System.out.println(json.toString());
//dataFromJsonExtractor.extractData(json);
}
private URI buildUri(){
URI link = null;
try {
URIBuilder builder = new URIBuilder(uriBase);
builder.setParameter("language", "de");
URI uri = builder.build();
link = uri;
}catch (URISyntaxException e){
logger.debug("Computer Vision API URL Builder creation error: " + e);
}
return link;
}
도움이 필요하십니까? 건배!
건배 !! Octet Stream의 ContentType에 대한 매력처럼 작동했습니다. 문서에 있지만 멀티 파트 양식에서는 작동하지 않았습니다. 기묘한. 감사. –