Skip to content

Instantly share code, notes, and snippets.

@pawlos
Created February 27, 2017 18:17
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save pawlos/514eb66717b76de3116aee78446e779e to your computer and use it in GitHub Desktop.
Vison API example
public static async Task<HttpResponseMessage> RequestImageAnalisys(byte[] data)
{
var client = new HttpClient();
var queryString = HttpUtility.ParseQueryString(string.Empty);
// Request headers
client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", ConfigurationManager.AppSettings["VisionAPI"]);
// Request parameters
queryString["visualFeatures"] = "Categories, Tags, Description, Faces, ImageType, Color, Adult";
queryString["details"] = "Celebrities";
queryString["language"] = "en";
var uri = "https://westus.api.cognitive.microsoft.com/vision/v1.0/analyze?" + queryString;
HttpResponseMessage response;
using (var content = new ByteArrayContent(data))
{
content.Headers.ContentType = new MediaTypeHeaderValue("application/octet-stream");
response = await client.PostAsync(uri, content);
}
return response;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment