2017-05-04 39 views
4

我正在学习ASP.Net MVC 5的基础知识。并且我想使用Advanced rest ClientSecurityController中的一个控制器动作发出POST请求。但我无法这样做。请指导我。如何使用Advanced Rest Client进行POST请求

下面是我的尝试:

[HttpPost] 
public ActionResult Hello(SampleMV viewModel) 
{ 
    return Content("Hello"); 
} 

public class SampleMV 
{ 
    public int one { get; set; } 
    public int two { get; set; } 
    public int? three { get; set; } 
} 

现在什么是我需要在我的高级REST客户端进行更改?

步骤1.设置要求下拉菜单POST

第2步:在原始有效载荷部分下面我补充明确:

one = 2, two = 3, three = 4 seperated by comma. 

我不知道这是正确的方式。

步骤3.我需要把一些内容类型或任何其他配置。目前,我的错误为Resource not found

这里是截图:

enter image description here 编辑:另一种尝试

+0

有效负载不是JSON,应该是JSON:'{“one”:2,“two”: 3,“three”:4}' – Gusman

+0

为什么你在URL中添加'/ security'?控制器是“SecurityController”吗? –

+0

我有我的securitycontroller – Unbreakable

回答

2

你的有效载荷的格式不正确,在JSON对象定义应该是{ "one":2, "two":3, "three":4 }

4

404意味着你有路由问题。它与有效载荷无关,因为它不会以任何方式对路线做出贡献。假设这种方法是SecurityController.Hello,而你使用的默认路由,以/security/hello请求应该去正确的地方。因此,将您的RouteConfig.cs包含在您的问题中也是有帮助的。

另外,如果你利用ApiController,我觉得动作名称必须遵循请求方法开始的惯例。换句话说,您的Hello操作需要命名为PostHello

一旦你排序的路由,你有要求身体JSON的方式,现在,应该可以正常工作。为了将来的参考,“原始”将需要应用程序/ x-www-form-urlencoded,即one=1&two=2&three=3

相关问题