Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/256.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从另一个项目获取HTTP Post值_C#_Http_Asp.net Core - Fatal编程技术网

C# 从另一个项目获取HTTP Post值

C# 从另一个项目获取HTTP Post值,c#,http,asp.net-core,C#,Http,Asp.net Core,我在一个解决方案中有两个项目。我必须把第一个项目的东西发到第二个项目 我在第一个项目中的发布方法: [HttpPost] [Route("count")] public async Task<ActionResult> Count(DateTime date) { var section = this._configuration.GetSection("product"); using

我在一个解决方案中有两个项目。我必须把第一个项目的东西发到第二个项目

我在第一个项目中的发布方法:

[HttpPost]
[Route("count")]
 public async Task<ActionResult> Count(DateTime date)
    {
       
        var section = this._configuration.GetSection("product");
        using (var httpClient = new HttpClient())
        {
            string countDate =JsonConvert.SerializeObject(date);
           
            httpClient.BaseAddress = new Uri(section.GetValue<string>("Host"));
            HttpResponseMessage responseMessage = await httpClient.PostAsync(section.GetValue<string>("Endpoint"), new StringContent(countDate));
            if(responseMessage.IsSuccessStatusCode)
            {
                var content = await responseMessage.Content.ReadAsStringAsync();
                var operationResult =  JsonConvert.DeserializeObject<ResultJSON>(content);
                int result = await _dataService.Counts(operationResult);
                return Ok(result);
            }
            else
            {
                return BadRequest();
            }
        }
    }

在这里,内容值为空。如何获取来自第一个项目的内容值?

更改StringContent,如下所示:

new StringContent(countDate, Encoding.UTF8, "application/json")
并将[FromBody]添加到第二个project post方法中:

public ActionResult Count([FromBody]string content)

Thx,我应用了您的解决方案,在这里得到了一个错误
DateTime date=(DateTime)JsonConvert.DeserializeObject(content)关于时间转换。我这样修改
DateTime date=DateTime.Parse(content)
public ActionResult Count([FromBody]string content)