0
私はMSのコンピュータビジョンAPiにOCRポストリクエストを行い、応答を返します:HTTP/1.1 415サポートされていないメディアタイプ[キャッシュコントロール: no-cache、プラグマ: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;
}
ヘルプがありますか?乾杯!
乾杯!あなたのContentTypeオクテットストリームの魅力のように働いていました。ドキュメント内にあっても、マルチパートフォームでは機能しませんでした。奇妙な。ありがとう。 –