### Call PhotoDNA REST API Source: https://www.microsoft.com/en-us/photodna/documentation Sample code demonstrating how to call the PhotoDNA REST API using a subscription key to validate images against a hash set. This is typically used after onboarding to the service. ```csharp using System; using System.Net.Http; using System.Net.Http.Headers; using System.Text; using System.Threading.Tasks; public class PhotoDNAClient { private readonly HttpClient _client; private readonly string _apiKey; public PhotoDNAClient(string apiKey) { _client = new HttpClient(); _apiKey = apiKey; _client.BaseAddress = new Uri("https://api.example.com/photodna/"); // Replace with actual API endpoint _client.DefaultRequestHeaders.Accept.Clear(); _client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); _client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _apiKey); } public async Task ValidateImageAsync(string imageUrl) { try { var requestBody = new { imageUrl = imageUrl }; var jsonBody = Newtonsoft.Json.JsonConvert.SerializeObject(requestBody); var content = new StringContent(jsonBody, Encoding.UTF8, "application/json"); HttpResponseMessage response = await _client.PostAsync("validate", content); response.EnsureSuccessStatusCode(); // Throw if not 2xx return await response.Content.ReadAsStringAsync(); } catch (HttpRequestException e) { Console.WriteLine($"Error calling PhotoDNA API: {e.Message}"); return null; } } public async Task ValidateImageBytesAsync(byte[] imageBytes) { try { var content = new ByteArrayContent(imageBytes); content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream"); HttpResponseMessage response = await _client.PostAsync("validate/bytes", content); response.EnsureSuccessStatusCode(); // Throw if not 2xx return await response.Content.ReadAsStringAsync(); } catch (HttpRequestException e) { Console.WriteLine($"Error calling PhotoDNA API: {e.Message}"); return null; } } // Example usage: // public static async Task Main(string[] args) // { // string apiKey = "YOUR_SUBSCRIPTION_KEY"; // var client = new PhotoDNAClient(apiKey); // // // Validate by URL // string imageUrl = "http://example.com/image.jpg"; // string resultUrl = await client.ValidateImageAsync(imageUrl); // Console.WriteLine($"Validation result (URL): {resultUrl}"); // // // Validate by bytes // byte[] imageBytes = System.IO.File.ReadAllBytes("path/to/your/image.jpg"); // string resultBytes = await client.ValidateImageBytesAsync(imageBytes); // Console.WriteLine($"Validation result (Bytes): {resultBytes}"); // } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.