如何使用httpwebrequest调用PUT方法?

时间:2016-09-30 15:30:19

标签: asp.net rest wcf httpwebrequest

Tried Code:

var request = WebRequest.Create("http://localhost/RestfulTutorialService/Service.svc/Post");
            request.Method = "PUT";
            request.ContentType = "application/json";
            using (var writer = new StreamWriter(request.GetRequestStream()))
            {

                var serializer = new JavaScriptSerializer();
                var payload = serializer.Serialize(objBlogPost);
                writer.Write(payload);

            }

            var response = (HttpWebResponse)request.GetResponse();
            var responseCode = response.StatusCode;

错误:远程服务器返回错误:(405)Method Not Allowed。

我的服务是一项宁静的服务。以下是被调用的方法。

    [OperationContract]
    [WebInvoke(Method = "PUT", UriTemplate = "/Post", RequestFormat = WebMessageFormat.Json)]
    void UpdateBlogPost(BlogPost post);

0 个答案:

没有答案