使用自定义标题和表单数据创建WebApi

问题描述 投票:0回答:1

我是WebApi开发的新手。我已经用GET创建了一个Basic Authentication请求。现在,我想在传递一些POSTcustom headers的同时创建form-data方法。以下是邮递员的示例屏幕截图

标题部分

enter image description here

正文部分

enter image description here

更新1

我正在执行以下操作

 [HttpPost]
    [Route ("aux_relay_operations/[controller]")]
    public HttpResponseMessage RelayMethod(HttpRequestMessage request)
    {
        var value = HttpContext.Current.Request.Form["test"];

        return Request.CreateResponse(HttpStatusCode.OK, value);
    } 

邮差

enter image description here

我在上面的方法上添加了一个调试点,但是它不在里面。

我一定做错了。

任何帮助将不胜感激

rest header asp.net-web-api2 postman form-data
1个回答
0
投票

您的路线似乎定义错误。我想(从您写的内容和邮递员的网址来看)应该是:

[Route("aux_relay_operations/[action]")]

在路由中包含[controller]表示您可能期望使用控制器名称。不过,作为第一个更改,我将按照此路线进行操作,然后查看是否可行:

[Route("aux_relay_operations/RelayMethod")]
© www.soinside.com 2019 - 2024. All rights reserved.