views:

705

answers:

1

I have my own Twitter API and I've received a couple emails about a problem when trying to post a status update with accent marks and other diacritics. I would like to encode these so that the status update still has them.

I know there are ways to remove the diacritic, but I would like to keep it.

I read the Twitter Counting Characters page and noticed that they did talk about encoding the diacritic. I would like to do this in C#. I am just not sure how to do it.

Here was the original bug report for the Twitter API http://code.google.com/p/twitter-api/issues/detail?id=433

I've tried using..

 string oldStatus = "con eñe";
 string newStatus = oldStatus.Normalize(NormalizationForm.FormD);

I've tried using FormC, FormKC, and FormKD, and I either get the 401 - Unauthorized error or a Invalid Unicode value in one or more parameters error.

Any ideas?

+1  A: 

Does this help? I tested the app this is from and it successfully posted my update using the diacritic in your post (and at 140 characters long).

HttpWebRequest request = CreateRequest("https://twitter.com/statuses/update.xml", "POST", 
username, password);
string str = HttpUtility.UrlEncode(status);
byte[] buffer = new UTF8Encoding(false, false).GetBytes("status=" + str);
using (Stream stream = request.GetRequestStream())
{
    stream.Write(buffer, 0, buffer.Length);
}
request.GetResponse().Close();
subkamran
Are you using OAuth? Since I am using OAuth, I don't write the byte data to the stream.
Eclipsed4utoo