【发布时间】:2020-10-29 15:17:48
【问题描述】:
我遇到的问题是使用 .Net Core 3.1 MVC 在 Power Automate 的发布请求中发送参数。我创建了一个具有参数名称和年龄的简单人员应用程序,然后一个视图有一个按钮,当您单击它时,它会回复 Power Automate HTTP 请求提供的 POST 请求,我将收到一封电子邮件,其中包含我的姓名和年龄设置为人物模型。但是每次我收到一封电子邮件时,它的姓名和年龄都是空的。下面提供一些细节是我的源代码:
索引.cshtml
<a asp-controller="Test" asp-action="SendNameAge" class="btn btn-success" >Json Trigger</a>
成功.cshtml
<p>success request</p>
失败的.cshtml
<p>Failed request</p>
模型.cs
using System;
using System.Collections.Generic;
using System.Text;
namespace WebApplication.Model
{
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
}
}
TestController.cs
using Microsoft.AspNetCore.Mvc;
using System;
using System.Net.Http;
using System.Threading.Tasks;
using WebApplication.Model;
using WebApplication.Utility;
namespace WebApplication.Controllers
{
public class TestController : Controller
{
public IActionResult Index()
{
return View();
}
public IActionResult Success()
{
return View();
}
public IActionResult Failed()
{
return View();
}
public async Task<IActionResult> SendNameAge()
{
using (var client = new HttpClient())
{
Person person = new Person
{
Name = "Juan Dela Cruz",
Age = 32
};
client.BaseAddress = new Uri(SD.ApiUri);
var response = await client.PostAsJsonAsync(SD.ApiUri, person);
if (response.IsSuccessStatusCode)
{
return RedirectToAction(nameof(Success), Json(response));
}
else
{
return RedirectToAction(nameof(Failed), Json(response));
}
}
}
}
}
然后这是我单击按钮时收到的电子邮件,也是我应该收到的带有参数的电子邮件,但我只是使用邮递员进行测试。
【问题讨论】:
标签: c# json.net httprequest asp.net-core-3.1 power-automate