Is there a way to do a PUT with WebClient?

后端 未结 4 669
悲&欢浪女
悲&欢浪女 2021-02-11 13:37

with the WebClient class in .NET 4.0, is there a way to do a PUT?

I know you can do a GET with DownloadString() and a POST with UploadString(), but is there a method or

4条回答
  •  执笔经年
    2021-02-11 14:25

    There are overloads for UploadString that let you specify the method. For example, this one takes a Uri, a string for the method, and a string for the data.

    using (var webClient = new WebClient())
    {
        webClient.UploadString(apiUrl, 
            WebRequestMethods.Http.Put, // or simply use "PUT"
            JsonConvert.SerializeObject(payload))
    }
    

提交回复
热议问题