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.
The UploadData method sends the content of data to the server without encoding it. If the method parameter specifies a verb that is not understood by the server, the underlying protocol classes determine what occurs. Typically, a WebException is thrown with the Status property set to indicate the error.
The UploadData method sends the content of data to the server without encoding it. This method blocks while uploading the data. To continue executing while waiting for the server's response, use one of the UploadDataAsync methods.
The UploadValues method sends a NameValueCollection to a resource using the method specified in the method parameter and returns any response from the server. This method blocks while uploading the data. To continue executing while waiting for the server's response, use one of the UploadValuesAsync methods.
The UploadData method sends a data buffer to a resource using the HTTP method specified in the method parameter, and returns any response from the server. This method blocks while uploading the data.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With