I am testing a webservice using c# and fiddler. My database has Chinese text stored..within my debugger i can see the chinese text stored into a c# variable FINE, however when I post the REQUEST using c# and debug it in fiddler, fiddler shows the text as Question Marks (???). why is that? hence my webservice is also seeing it as ????.
here is my code sample
public confirmationStatus Send(string phoneNumber, string text)
{
messages_send model = new messages_send() { contacts = new List<string>() { phoneNumber }, text=text };
string url = this.setupUrl();
string dataToSend = new JavaScriptSerializer().Serialize(model);
var cli = new WebClient();
cli.Headers[HttpRequestHeader.ContentType] = "application/json;charset=utf-8";
string response = cli.UploadString(url, dataToSend);
return new JavaScriptSerializer().Deserialize<confirmationStatus>(response);
}
and this is how Fiddler sees it.
POST https://api.***.com/v1/messages? HTTP/1.1
Content-Type: application/json
Host: api.**.com
Content-Length: 1061
Expect: 100-continue
Connection: Keep-Alive
{"contacts":["+1*****9"],"text":"**??HME??????** John,??? 01-01-0001 ???? 12:00 AM ? 12:00 AM? ????????????????????: Link: https://www.****.com/timesheets/?v=0 .Text STOP "}
Problem was, .NET encodes strings to UTF-16 by default. hence Fiddler and my webservice was unable to encode it properly and showing question marks.
Changing the ContentType of HTTP Headers did not do the trick. I changed the encoding of WebClient object and it worked.
Hence the Answer for me was...
var cli = new WebClient(); cli.Encoding = Encoding.UTF8;
in .NET we can change the encoding for streams, so I believe thats why it worked.