消费 REST 完整服务 POST c#

Consuming REST full service POST c#

我创建了很多基本都是get请求的rest端点。 但现在我必须创建一个 post 请求。 这是我的 OperationContract

[OperationContract]
        [WebInvoke(Method = "POST",
            UriTemplate = "Product/Save",
            ResponseFormat = WebMessageFormat.Json,
            RequestFormat = WebMessageFormat.Json)]
        ServiceResult Save(ProductInfo request);

谁能告诉我如何在控制台应用程序中使用这个 POST 请求?

我参考了Consuming REST Service pb

但是 HttpWebRequest 在我的 .net frame work 4.0/visual sudio 2012 中被标记为过时

我已经使用 HttpListener Class(获取请求)完成了它:

https://msdn.microsoft.com/it-it/library/system.net.httplistener%28v=vs.110%29.aspx

和 HttpListenerResponse(发送响应):

https://msdn.microsoft.com/it-it/library/system.net.httplistenerresponse%28v=vs.110%29.aspx

Use HttpClient instead of HttpWebRequest