Is there a way to do a PUT with WebClient?

时光总嘲笑我的痴心妄想 提交于 2019-12-09 07:27:18

问题


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 property that lets you do a PUT?

Thanks.


回答1:


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.




回答2:


You can use webclient.UploadString(urlwithparams,"Put","")

url with params should include the params in querystring format ... urlwithparams = www.foo.com?key=value&key2=value2

This worked for me...




回答3:


Huh? As stated on MS's website WebClient.UploadData does take the method (as a string) too right? Or am I missing something?




回答4:


I don't think that WebClient can do it. However, you can use the HttpWebrequest class to perform a put request.



来源:https://stackoverflow.com/questions/8346750/is-there-a-way-to-do-a-put-with-webclient

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!