public async Task <IHttpActionResult> PostTakePhoto(TokenForm token) { UriBuilder uriBuilder = new UriBuilder(Program.ServerUrl); uriBuilder.Path = "/api/photos"; uriBuilder.Query = "tokenid=" + token.tokenid; if (ModelState.IsValid) { Console.WriteLine("Received hsid: " + token.tokenid); Task <Vector> CaptureImageAsync = Task.Run <Vector>(() => CaptureImage()); Vector image = await CaptureImageAsync; HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.PostAsync(uriBuilder.Uri, new ByteArrayContent((byte [])image.get_BinaryData())); if (response.IsSuccessStatusCode) { EntityIdResponse scan = await response.Content.ReadAsAsync <EntityIdResponse>(); return(Created(response.Headers.Location, scan)); } else { return(InternalServerError(new ServerResponseError(response))); } } else { return(BadRequest("Expected hsid")); } }
async Task <FingerPrintResponse> PostBitmapAsync(byte[] imageBytes, string tokenid) { var serverUri = buildRestUri(tokenid, "scan"); Console.WriteLine("POST fingerprint bitmap to: " + serverUri); HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.PostAsync(serverUri, new ByteArrayContent(imageBytes)); Console.WriteLine("POST scanned bitmap response code: " + response.StatusCode + " " + response.ReasonPhrase); Console.WriteLine("POST scanned bitmap response: " + await response.Content.ReadAsStringAsync()); if (response.IsSuccessStatusCode) { Console.WriteLine("The scan was created successfully on server."); EntityIdResponse scan = await response.Content.ReadAsAsync <EntityIdResponse>(); Console.WriteLine("\tscan.id = " + scan.id); Console.WriteLine("\tLocation: " + response.Headers.Location); foreach (var h in response.Headers) { Console.WriteLine("\t" + h.Key + ": " + h.Value); } Uri locationHeader; if (response.Headers.Location != null) { locationHeader = response.Headers.Location; } else { Console.WriteLine("Creating Location header manually"); var locationBuilder = new UriBuilder(Program.ServerUrl); locationBuilder.Path = "/api/fingerprintscans/" + scan.id; locationHeader = locationBuilder.Uri; } Console.WriteLine("Sending Location header: " + locationHeader); return(new FingerPrintResponse { FingerprintId = scan, FingerprintLocaltion = locationHeader }); } else { throw new ServerResponseError(response); } }