ISO-8859 encode post request content C#

I am trying to send a POST request in C# with a parameter encoded to ISO-8859. I am using this code:

        using (var wb = new WebClient())
            var encoding = System.Text.Encoding.GetEncoding("ISO-8859-1");

            var encodedText = System.Web.HttpUtility.UrlEncode("åæ ÆÆ øØ ø", encoding);
            wb.Encoding = encoding;

            wb.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            var data = new NameValueCollection();
            data["TXT"] = encodedText;

            var response = wb.UploadValues(_url, "POST", data);

I have figured out that the correctly encoded string for "åæ ÆÆ øØ ø" is %E5%E6+%C6%C6++%F8%D8+%F8, and I can see when debugging that encodedText actually is this string. However when inspecting the raw request in fiddler, I can see that the string looks like this: TXT=%25e5%25e6%2B%25c6%25c6%2B%25f8%25d8%2B%25f8. I am guessing some kind of extra encoding is being done to the string after or during the call to UploadValues().

Thank you so much in advance.


I checked Google for this. According to another question here on SO at UTF32 for WebClient.UploadValues? (second answer), Webclient.UploadValues() indeed does encoding itself. However, it does ASCII encoding. Youll have to use another method to upload this, like HttpWebRequest.

Need Your Help

How to exclude .cpan folder from rsync?

backup rsync cpan permission-denied

I use rsync to backup the home directory (ext4) of my Ubuntu installation. I use the following command to copy files and folders to a remote server (ext4).

Vertica role grant not working

sql vertica

I am trying to setup a new role for making the access rights granting easier. I was wondering if there is an easier way to give select on all tables (newly created tables should be accessible

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.