title: Post JSON string to RESTful API using C# ASP.NET MVC async
body: <p>I'm having trouble with sending a post request to a RESTful API. The API expects the following JSON body:</p>
  
  <blockquote>
    <p>{     "APIKey":"String content",  "ID":"String content",  "Data":"String
    content",     "TokenScheme":0 }</p>
  </blockquote>
  
  <p>I'd like for it to use async but this is a first for me and I'm having issues just handling the return string. I'd just like to know how to send the string data to the view and I'll get it from there.</p>
  
  <p>Here is what I'm trying to use but the browser just spins and spins.</p>
  
  <pre><code>public async Task&lt;string&gt; RunAsync()
  {
      using (var client = new HttpClient())
      {
          // TODO - Send HTTP requests
          client.BaseAddress = new Uri("https://test-api.com/Services.svc/");
          client.DefaultRequestHeaders.Accept.Clear();
          client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
          string APIKey, ID, Data, Scheme;
  
          // HTTP POST
          string[] jsonRequest = { APIKey = "", ID = "", Data = "teststring", Scheme = "0" };
          //alt option IHttpActionResult 
          HttpResponseMessage response = await client.PostAsJsonAsync("REST/Service", jsonRequest);
          if (response.IsSuccessStatusCode)
          {
              Debug.WriteLine(@"             successful.");
              return "";
          }
          else
          {
              Debug.WriteLine(@"             Failed.");
              return "";
          }
      }
  }
  </code></pre>