public async Task <IAnalyzeResult> UploadAndAnalyzeImage(byte[] imageBytes, params System.Enum[] features) { HttpClient client = new HttpClient(); //getToken string token = BaiduAccessToken.getAccessToken(Key, SecretKey).access_token; string uri = API + "?" + $"access_token={token}"; //getBase64 string base64String = Convert.ToBase64String(imageBytes); string jsonContent = this.threshold == null ? $"{{\"image\":\"{base64String}\"}}" : $"{{\"threshold\":\"{this.threshold}\",\"image\":\"{base64String}\"}}"; byte[] buffer = Encoding.Default.GetBytes(jsonContent); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "post"; request.KeepAlive = true; request.ContentLength = buffer.Length; request.GetRequestStream().Write(buffer, 0, buffer.Length); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.Default); string contentString = reader.ReadToEnd(); //HttpResponseMessage response; //using (HttpContent content = new StringContent(jsonContent)) //{ // // Make the REST API call. // response = await client.PostAsync(uri, content); //} //string contentString = await response.Content.ReadAsStringAsync(); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception(contentString); } // Get the JSON response. // Display the JSON response. Console.WriteLine("\nResponse:\n"); Console.WriteLine(VisCommonClass.JsonPrettyPrint(contentString)); return(JsonConvert.DeserializeObject <BaiduAnalyzeResult>(contentString)); }