WebClient.UploadData proper use for mail request

I think I'm a little crazy when I test this on my local web server, it works fine when I go to the website, it returns an empty string instead of the data I expect

I am not familiar with C #, so I just wanted to check that I was doing everything right. data is just ascii text

wc = new WebClient(); wc.Headers.Add("Content-Type", "application/x-www-form-urlencoded"); response = wc.UploadData(this.urlUpdate, Encoding.ASCII.GetBytes("data=" + HttpUtility.UrlEncode(buf.ToString()))); s = Encoding.ASCII.GetString(response); 
+6
c # webclient
source share
1 answer

It really depends on what you are trying to do ... I am not sure, for example, why you are url encoding data in the body. An easier way to publish key / value pairs using UploadValues ;

 NameValueCollection inputs = new NameValueCollection(); string value = ... inputs.Add("data", value); webClient.UploadValues(address, inputs); 
+12
source share

All Articles