2017-05-04 109 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

相關問題