.NET WebClient.UploadValues vs WebClient.UploadData

一曲冷凌霜 提交于 2019-12-04 01:07:43

问题


I am writing a class library to perform operations on a site outside my control. The site is accepting form-posts as input.

Can anyone tell me if there is a difference between these two methods except the form of the data to upload?

    System.Net.WebClient.UploadData(Uri, Byte[]);

    System.Net.WebClient.UploadValues(String, NameValueCollection);

I have no objections to arrange data either way, but started to wonder what the difference actually is, and it is still nagging me in some strange way, not knowing if there is a difference.


回答1:


Both "POST" the data to the server. If you use UploadValues, the values will be made available to the server in the Request.Form collection which is how a normal HTML form works. UploadData gives you more flexibility since no escaping is performed on your data. Its up to you to format the data in a way that the server will understand. As a consequence of this, you can use UploadData to duplicate the behavior of UploadValues.



来源:https://stackoverflow.com/questions/5539245/net-webclient-uploadvalues-vs-webclient-uploaddata

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