예제 #1
0
        public static async Task <CustomImageResponse> AnalyzeImage(string imagePath)
        {
            client.DefaultRequestHeaders.Add("Prediction-Key", subscriptionKey);
            string uri = uriBase;

            HttpResponseMessage response;

            byte[] byteData = GetImageAsByteArray(imagePath);
            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");

                // Make the REST API call.
                response = await client.PostAsync(uri, content);
            }

            // Get the JSON response.
            var result = await response.Content.ReadAsStringAsync();

            CustomImageResponse imageResponse = null;

            if (response.IsSuccessStatusCode)
            {
                imageResponse = CustomImageResponse.FromJson(result);
            }
            return(imageResponse);
        }
예제 #2
0
 public static string ToJson(this CustomImageResponse self) => JsonConvert.SerializeObject(self, ApiLibrary.Converter.Settings);