title: Sending HTTP post request in C# to Microsoft Bing speech API
body: <p>I am trying to send a HTTP post request to microsoft Bing speech API o transcribe an audio file. First we need to send a post request to get an "access token" as a response, then this token is used (as authorisation" in another post request to upload the actual file and get the transcription in the response. I can send the first post request and successfully get the access token, but I am not able to get a reasonable response for my second post request. I follow this page: <a href="https://www.microsoft.com/cognitive-services/en-us/speech-api/documentation/api-reference-rest/bingvoicerecognition" rel="nofollow">https://www.microsoft.com/cognitive-services/en-us/speech-api/documentation/api-reference-rest/bingvoicerecognition</a></p>
  
  <p>This is the second post request:</p>
  
  <pre><code>        Guid requestId = Guid.NewGuid();
          var Uri = @"https://speech.platform.bing.com/recognize?version=3.0&amp;requestid=" + requestId.ToString() + @"&amp;appID=D4D52672-91D7-4C74-8AD8-42B1D981415A&amp;format=json&amp;locale=en-US&amp;device.os=Windows%20OS&amp;scenarios=ulm&amp;instanceid=f1efbd27-25fd-4212-9332-77cd63176112";
          HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, Uri);
  
          request.Headers.Add("Authorization", String.Format("Bearer {0}", accessToken));
          request.Headers.TryAddWithoutValidation("Content-Type", @"audio/wav; samplerate=16000");
          MemoryStream ms = new MemoryStream();
          using (var fs = System.IO.File.OpenRead("audio.wav"))
          {
              byte[] buffer = new byte[1024 * 8];
              while (fs.Read(buffer, 0, buffer.Length) &gt; 0)
              {
                  ms.Write(buffer, 0, buffer.Length);
              }
              fs.Close();
          }
          ms.Seek(0, SeekOrigin.Begin);
  
          HttpContent _Body = new StreamContent(ms);
          request.Content = _Body;
          var client2 = new HttpClient();
          var response2 = client2.SendAsync(request);
  </code></pre>
  
  <p>I guess the problem is where I set the "Content-Type" for the header. The reason is when I debug, I don't see this property being set in the Header of the request. In fact, there is no Content-Type in the header. Any help would be appreciated. This page, which talks about the equivalent <code>curl</code> command, can also be helpful: <a href="https://social.msdn.microsoft.com/Forums/en-US/ad73e4f1-e576-4080-9fe7-060cc2f583ca/microsoft-bing-voice-recognition-api-authorization-404resource-not-found?forum=SpeechService" rel="nofollow">https://social.msdn.microsoft.com/Forums/en-US/ad73e4f1-e576-4080-9fe7-060cc2f583ca/microsoft-bing-voice-recognition-api-authorization-404resource-not-found?forum=SpeechService</a></p>