首页 > 解决方案 > asp.net web API 通过 body form-data 发布数据

问题描述

我正在使用邮递员通过 body-> form-data 将数据发送到我的 Web API

这是我的代码

public class get_CustomerSignIn
{       
        public string mobile { get; set; }   
        public string password { get; set; }
} 

public HttpResponseMessage Post(get_CustomerSignIn Gsign)
{
string mobile = Gsign.mobile;
string password = Gsign.password;
        
.......etc
        
        
}

在这种情况下,我收到错误,我的模型对象为空,但是在 postman 中使用 body->raw->json 发布时它的工作

只是我的问题是如何将表单数据直接放入我的模型对象中。?(我无法将帖子类型更改为 x-www-form-urlencoded )

标签: asp.netasp.net-web-apimultipartform-data

解决方案


您可以使用以下代码获取表单数据值:

HttpContext.Current.Request.Form["Your key"];

推荐阅读