C# 如何使用 POSTMAN 或任何客户端工具应用程序调用 RestFul WCF POST 服务?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17733007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to call RestFul WCF POST service using POSTMAN or any client tool application?
提问by user1429595
okay lets say I want to use POSTMAN or any other Rest service client tool to call my code, how should can I do it? one of my parameters "data" is huge and I dontwant include the "data" or payload in URL, I want to call it from the body?
好吧,假设我想使用 POSTMAN 或任何其他 Rest 服务客户端工具来调用我的代码,我该怎么做?我的参数“数据”是一个巨大的,我不希望包括URL中的“数据”或有效载荷,我想从身体打电话了吗?
here is the actual code
这是实际的代码
[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;
}
any help would be appreciated it
任何帮助将不胜感激
Thanks
谢谢
回答by Rajesh
回答by Ivan Cipriani
In Postman you have to write this string http://localhost/Sample/Service1.svc/createNewSurveyin the box "Enter the request URL" and selected POST, add in the header these two keys:
在 Postman 中,您必须在“输入请求 URL”框中输入此字符串http://localhost/Sample/Service1.svc/createNewSurvey并选择 POST,在标题中添加以下两个键:
- Content-Type:application/json
- Host:localhost
- 内容类型:应用程序/json
- 主机:本地主机
and in the body select "raw" radio button and write:
并在正文中选择“原始”单选按钮并写入:
- {"id":"5","Data":"sample data to be sent to server"}
- {"id":"5","Data":"要发送到服务器的样本数据"}