Request.Form返回空数据

时间:2018-07-18 14:22:34

标签: c# asp.net-mvc

我正在使用两个API。一个正在发送数据,另一个正在接收数据,然后对其进行一些处理。这是代码:

发件人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);  
            ....  
            ....  
    }  
}  

接收器API:

var campaignId = HttpContext.Current.Request.Form["CampaignId"];  //also tried with Request.Params["CampaignId"] but here the Request.Form is always null

当我序列化一个对象然后将其发送到接收器API时,此技术始终对我有用。但是这里只有1个变量(campaignId),所以我不想使用任何模型。这种语法有什么问题吗?

0 个答案:

没有答案