2013-07-18 27 views
1

好吧,讓我說我想用POSTMAN或任何其他Rest服務客戶端工具來調用我的代碼,我該怎麼做呢?我的一個參數「數據」是巨大的,我不要想在URL中包含「數據」或有效載荷,我想從身體調用它?如何使用POSTMAN或任何客戶端工具應用程序調用RestFul WCF POST服務?

下面是實際的代碼

[OperationContract(Name = "createNewSurvey")] 
    [WebInvoke(Method = "POST", ResponseFormat = WebMessageFormat.Json, BodyStyle = WebMessageBodyStyle.Wrapped, UriTemplate = "post/createNewSurvey")] 
    string CreateNewSurvey(string id, string Data); 


public string CreateNewSurvey(string id, [FromBody]string Data) 
    { 
     //do somethoinf 
     return data; 
    } 

任何幫助,將不勝感激它

感謝

回答

0

安裝一個叫Fiddler工具,然後使用下面的原始請求。

URL:http://localhost/Sample/Service1.svc/post/createNewSurvey 
User-Agent: Fiddler 
Content-Type: application/json 
Host: localhost 

{"id":"5","Data":"sample data to be sent to server"} 
+0

爲什麼沒有郵遞員? –

5

在郵差你必須寫這個字符串http://localhost/Sample/Service1.svc/createNewSurvey在框「中輸入請求的URL」,並選擇了POST,添加在標題中這兩個鍵:

  • 內容類型:應用程序/ JSON
  • 主機:本地主機

,並在身體中選擇 「原始」 單選按鈕,並寫上:

  • { 「ID」: 「5」, 「數據」: 「樣本數據被髮送到服務器」}

see the image like example

相關問題