使用https://docs.microsoft.com/zh-cn/azure/cognitive-services/computer-vision/quickstarts/csharp上的MS Cognitive Services示例应用程序中 的代码,尝试运行以下代码时出现错误404 imageFilePath设置本地JPEG文件:
static async void MakeAnalysisRequest(string imageFilePath)
{
HttpClient client = new HttpClient();
// Request headers.
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
// Request parameters. A third optional parameter is "details".
string requestParameters = "visualFeatures=Description&language=en";
// Assemble the URI for the REST API Call.
string uri = uriBase + "?" + requestParameters;
HttpResponseMessage response;
// Request body. Posts a locally stored JPEG image.
byte[] byteData = GetImageAsByteArray(imageFilePath);
using (ByteArrayContent content = new ByteArrayContent(byteData))
{
// This example uses content type "application/octet-stream".
// The other content types you can use are "application/json" and "multipart/form-data".
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
// Execute the REST API call.
response = await client.PostAsync(uri, content);
// Get the JSON response.
string contentString = await response.Content.ReadAsStringAsync();
// Display the JSON response.
Console.WriteLine("\nResponse:\n");
Console.WriteLine(JsonPrettyPrint(contentString));
}
subscriptionKey是我的Azure订阅提供的两个密钥中的KEY1(在澳大利亚东部位置),而uribase是
const string uriBase = "https://australiaeast.api.cognitive.microsoft.com/vision/v1.0";
KEY1和uriBase的组合可与位于以下位置的API演示一起正常使用
https://australiaeast.dev.cognitive.microsoft.com/docs/services/56f91f2d778daf23d8ec6739/operations/56f91f2e778daf14a499e1fa/console
当目标文件是URL而不是本地文件时。图像已正确分析。
相关分类