asp.net - 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 )
解决方案
您可以使用以下代码获取表单数据值:
HttpContext.Current.Request.Form["Your key"];
推荐阅读
- go - 将多个映射组合成一个映射,其给定键的值是组合映射中键的值的总和
- java - 如何使用@RestControllerAdvice 全局处理异常(如 ResourceNotFoundException、NullPointerException 等)?
- linux - 使用 grep 进行文件搜索,不包括结果中的字段
- javascript - 打包 JavaScript 函数
- android - 修复 Bitrise 脚本失败的 Git 日志命令需要做些什么
- bash - 如何将包含完整路径的文件移动到子文件夹?
- php - 错误 403 - 没有 storage.objects.create 访问权限
- java - SQL IN Query 是性能更好还是 Java 方法 ContainsAll
- pandas - 额外的引号被添加到数据框中的字符串字段
- amazon-web-services - AWS IAM 角色和 STS