title: HttpClient C# Post
body: <p>I've done a POST request with the HTTPClient class but now I'm struggling a bit. How can I achieve displaying it on my website? The goal is to post a json ( currently in a string) and then display it on the site again. As you can see my POST command goes to the home controller in mvc and then the about action. How can I now get the data and return it to a view?</p>
  
  <pre><code>public ActionResult About(string json)
  </code></pre>
  
  <p>Does adding paramters like this work? And if so how do I do it properly?</p>
  
  <p>This is the method call:</p>
  
  <pre><code>post(JsonConvert.SerializeXmlNode(pack));
  </code></pre>
  
  <p>This is the method itself:</p>
  
  <pre><code>async Task post(string jsonText)
  {
                      // Create a New HttpClient object and dispose it when done, so the app doesn't leak resources
        using (HttpClient client = new HttpClient())
        {
        // Call asynchronous network methods in a try/catch block to handle exceptions
            try
            {
                 StringContent json = new StringContent(jsonText, Encoding.UTF8, "application/json");
                 HttpResponseMessage response = await client.PostAsync("http://localhost:60000/home/about", json);
                 response.EnsureSuccessStatusCode();
                 string responseBody = await response.Content.ReadAsStringAsync();
                 // Above three lines can be replaced with new helper method below
                 // string responseBody = await client.GetStringAsync(uri);
  
                 Console.WriteLine(responseBody);
                 }catch (HttpRequestException e)
                 {
                      Console.WriteLine("\nException Caught!");
                      Console.WriteLine("Message :{0} ", e.Message);
                 }
             }
        }
  </code></pre>
  
  <p><strong>Update</strong></p>
  
  <p>How can i give the PostAsync command my own class? It forces me give it a HttpContent.</p>
  
  <p>As suggested i have created a new method to cache the whole data but what parameter do i have to give the method which saves the data to receive the class or httpcontent? (in the controller)</p>
  
  <pre><code> [HttpPost]
          public HttpResponseMessage Data(//What parameter?)
          {
              //SaveData
  
              return new HttpResponseMessage(HttpStatusCode.OK);
  
          }
  </code></pre>