需要实现的功能:对接口发一个pwd+data,我返回一个code和msg,然后把data展示到winform界面上(使用什么控件呢?,要怎么触发呢?怎么写代码能把data拿过来呢?)
这是我写的控制器代码,后面不知道怎么写了
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
namespace PopUpByMessage.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class MyWebApiController : ControllerBase
{
private readonly ILogger<MyWebApiController> _logger;
public MyWebApiController(ILogger<MyWebApiController> logger)
{
_logger = logger;
}
[HttpPost("[action]")]
public IActionResult SayHello(string pwd, string data)
{
if (pwd != "1")
{
object obj = new
{
code = "0",
msg = "请求失败"
};
return new JsonResult(obj);
//return new BadRequestResult();
}
else
{
object obj = new
{
code = "1",
msg = "请求成功"
};
return new JsonResult(obj);
}
}
}
}
这是form1界面的代码
public partial class Form1 : Form
{
private Lazy<IHost> webhost = new Lazy<IHost>(() => { return CreateHostBuilder().Build(); });
public static IHostBuilder CreateHostBuilder() =>
Host.CreateDefaultBuilder()
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.UseKestrel(o => { o.ListenAnyIP(9527); });
webBuilder.UseStartup<Startup>();
});
private async void button1_Click(object sender, EventArgs e)
{
await webhost.Value.StartAsync();
MessageBox.Show("启动成功!");
}