title: HttpClient postasync with custom header and application/json for body C#
body: <p>Hello I want to run push app center from its <code>api</code>. But I don't know how to make the proper format.</p>
  
  <p>I want to <code>postasync</code> from this api: <a href="https://appcenter.ms/api/v0.1/apps/KacangIjo/ShopDiaryApp/push/notifications" rel="nofollow noreferrer">https://appcenter.ms/api/v0.1/apps/KacangIjo/ShopDiaryApp/push/notifications</a></p>
  
  <p>What it needs for Headers is:
  X-API-Token ="{api token}" and Content Type="application/json"</p>
  
  <p>For the body(content) I want to put this:</p>
  
  <pre><code>{
      "notification_content" : {
          "name" : "Campaign Name",
          "title" : "Expired Warning",
          "body" : "You have items that almost expired"
      }
  }
  </code></pre>
  
  <p>I have difficulties how to write in the correct format for HttpClient.
  I tried this and no work..</p>
  
  <pre><code>Content = new Content
  {
     Name = "Campaign Name",
     Title = "Expired Warning",
     Body = "You have items that almost expired"
  };
  using (var client = new HttpClient { Timeout = TimeSpan.FromSeconds(30) })
  {
     var myContent = JsonConvert.SerializeObject(data);
     client.DefaultRequestHeaders.Add("X-API-Token", "{my api token}");
     client.DefaultRequestHeaders.Accept.Add(new 
     MediaTypeWithQualityHeaderValue("application/json"));
     var builder = new UriBuilder(new Uri("https://appcenter.ms/api/v0.1/apps/KacangIjo/ShopDiaryApp/push/notifications"));
     HttpResponseMessage response = await client.PostAsync(builder.Uri, content);
  };
  </code></pre>
  
  <p>But I know this code:</p>
  
  <pre><code> {
          "notification_content" : {
              "name" : "Campaign Name",
              "title" : "Expired Warning",
              "body" : "You have items that almost expired"
          }
      }
  </code></pre>
  
  <p>is not same with this to convert the json format:</p>
  
  <pre><code>Content = new Content
  {
      Name = "Campaign Name",
      Title = "Expired Warning",
      Body = "You have items that almost expired"
  };
  </code></pre>
  
  <p>Can help me with the correct Serialize Json Format? and the correct format of httpclient header and body?
  I already found lot of sample but still no clue with the one that I want.
  Really appreciate your help guys :)</p>