Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.NET WebClient.UploadValues vs WebClient.UploadData

Tags:

.net

webclient

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.

like image 944
Guidhouse Avatar asked Apr 04 '11 13:04

Guidhouse


People also ask

What does uploaddata do in Java?

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.

What is uploaddata async?

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.

What is uploadvaluesasync method?

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.

How does uploaddata work in Laravel?

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.


1 Answers

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.

like image 115
David Avatar answered Sep 19 '22 09:09

David