I am working with two APIs. One is sending data and another one is receiving data, then do some work with it. Here is the code:
Sender API:
var campaignId = "1234";
if (campaignId != null)
{
using (var client = new HttpClient())
{
var httpContent = new StringContent(
JsonConvert.SerializeObject(
new { CampaignId = campaignId }),
Encoding.UTF8,
"application/json"); //also tried with application/x-www-form-urlencoded
var uri = new StringBuilder(_domain)
.Append("/api/mailchimp/campaign/send");
var response = await client.PostAsync(uri.ToString(), httpContent);
....
....
}
}
Receiver API:
var campaignId = HttpContext.Current.Request.Form["CampaignId"]; //also tried with Request.Params["CampaignId"] but here the Request.Form is always null
This technique always works for me when I serialize an object and then send it to the receiver API. But here there is only 1 variable (campaignId) so I don't want to use any model. Is there anything wrong with this syntax?