POST as UTF8 - German characters

349 Views Asked by At

I'm trying to send a post as UTF8 using JSON data, from what i can see I'm correctly converting to UTF8 but i still get the data interprited as the unicode code point:

param = "method=setCategories&s=101";
param += "method=setCategories&s=101;

var name = HttpUtility.UrlEncode("geschirrspüler");
param += "&categories[02][dummies]=name;

So at this point the post request is as follows:

method=setCategories&s=101&method=setCategories&s=101&categories[02][dummies]=geschirrsp%c3%bcler

I then further encode to a UTF8 byte array and send the data:

HttpWebRequest req = (HttpWebRequest)WebRequest.Create("http://xxx.de/xxx.php");

json = <JSONobject>(param)

req.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(json);

req.ContentLength = byteArray.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.ServicePoint.Expect100Continue = false;

Stream requestStream = req.GetRequestStream();
requestStream.Write(byteArray, 0, byteArray.Length);

HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
StreamReader reader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);

json_data = reader.ReadToEnd();

So here's where the issue is, the return data on the request highlights the word geschirrspüler as being interprited as geschirrsp\u00fcler (the unicode).

Before going back to the guy that owns the web service and accusing him of interpriting it incorrectly on his side i want to ensure I'm definitly doing all that's neccesary to send correct UTF8 encoding for the ü character.

Thanks in advance.

0

There are 0 best solutions below