我正在尝试使用 Microsoft Custom Vision了解更多。我需要发出 HTTP 请求来发送要分析的图像。我成功地从 C# 发出请求,所以我知道信息是正确的。
但是,当我尝试在 Java 中发出相同的请求时,我收到了 HTTP 400 错误。
我相信我没有在 Java 中正确处理请求。真的吗?
以下是片段。
C#:
var client = new HttpClient();
client.DefaultRequestHeaders.Add("Prediction-Key", PredicitionKey);
using (var content = new
ByteArrayContent(byteData))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response = await client.PostAsync(url, content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
爪哇:
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Prediction-Key", predicitionKey);
connection.setRequestProperty("Content-Type", "application/octet-stream");
connection.setDoInput(true);
connection.setDoOutput(true);
connection.getOutputStream().write(data.getData());
connection.connect();
Reader in = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));
跃然一笑
慕后森
随时随地看视频慕课网APP
相关分类