Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-mvc/16.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# 以application/x-www-form-urlencoded格式从邮递员向Web API控制器发送数据_C#_Asp.net Mvc_Asp.net Core_Asp.net Web Api_Asp.net Web Api2 - Fatal编程技术网

C# 以application/x-www-form-urlencoded格式从邮递员向Web API控制器发送数据

C# 以application/x-www-form-urlencoded格式从邮递员向Web API控制器发送数据,c#,asp.net-mvc,asp.net-core,asp.net-web-api,asp.net-web-api2,C#,Asp.net Mvc,Asp.net Core,Asp.net Web Api,Asp.net Web Api2,我正在将一些数据从邮递员发送到web api控制器,但它没有击中我,我是否遗漏了什么 下面是我的代码 [HttpPost] [Route("[controller]")] [Consumes("application/x-www-form-urlencoded")] public ActionResult<Root> PostData([FromBody] Root inputData) { //StringBuilder sb = n

我正在将一些数据从邮递员发送到web api控制器,但它没有击中我,我是否遗漏了什么

下面是我的代码

[HttpPost]
[Route("[controller]")]
[Consumes("application/x-www-form-urlencoded")]
public ActionResult<Root> PostData([FromBody] Root inputData)
{
    //StringBuilder sb = new StringBuilder();
    //sb.Append("q:" + inputData.q + " siteKey:" + inputData.siteKEY + " siteCredentials:" + inputData.siteCredential + " user:" + inputData.userID + " patient:" + inputData.patientID + " uuid:" + inputData.UUID);
    return Ok(inputData); //(sb.ToString());
}
[HttpPost]
[路线(“[控制器]”)]
[使用(“应用程序/x-www-form-urlencoded”)]
公共操作结果PostData([FromBody]根输入数据)
{
//StringBuilder sb=新的StringBuilder();
//sb.追加(“q:+inputData.q+”siteKey:+inputData.siteKey+”siteCredentials:+inputData.siteCredential+”用户:+inputData.userID+”患者:+inputData.patientID+“uuid:+inputData.uuid”);
返回Ok(inputData);/(sb.ToString());
}

应用程序/x-www-form-urlencoded与URL末尾的查询字符串大致相同。所以移除

[Consumes("application/x-www-form-urlencoded")]

当使用Postman时,最好使用raw和json来创建输入参数

尝试关闭Postman设置上的“ssl证书验证”
只需转到设置->常规->关闭ssl证书验证

[FromForm]
属性用于从内容类型
应用程序/x-www-url-formencoded发送的提交表单中输入数据,而
[FromBody]
将以默认方式解析模型,在大多数情况下,哪些是由内容类型
应用程序/json
从请求主体发送的。

您看到了什么错误?404?405方法不允许您显示根类pls吗?我可能只是在这里吐球,但如果您使用启动程序时自动生成的Weatherforecast控制器,您的api控制器本身将具有
路由(“[controller]”
标记。因此,如果您在端点上方也放置了另一个标记,那么您试图查找的URL应该是:
host:port/WeatherForecast/WeatherForecast
。如果不是这个问题,请尝试将
[FromBody]
更改为
[FromForm]
公共类根{public Args Args{get;set;}公共字符串数据{get;set;}公共文件文件{get;set;}公共表单Json表单{get;set;}公共头文件{get;set;}公共Json{get;set;}公共字符串url{get;set;}}我做了,但没有任何效果
[HttpPost]
[Route("[api/Home/PostData]")]                   //check here please specify controllername and index name
[Consumes("application/x-www-form-urlencoded")]
public ActionResult<Root> PostData([FromBody] Root inputData)
{
    //StringBuilder sb = new StringBuilder();
    //sb.Append("q:" + inputData.q + " siteKey:" + inputData.siteKEY + " siteCredentials:" + inputData.siteCredential + " user:" + inputData.userID + " patient:" + inputData.patientID + " uuid:" + inputData.UUID);
    return Ok(inputData); //(sb.ToString());
}

[Route("[api/Home/PostData]")]                   //check here please specify controllername and index name