How to encode diacritics for Twitter updates?

I have my own Twitter API, and I received a couple of emails about the problem when trying to post a status update using accents and other diacritics. I would like to encode them so that they are updated.

I know that there are ways to remove diacritics, but I would like to keep it.

I read the Twitter page of Counting Characters and noticed that they were talking about coding diacritics. I would like to do this in C #. I'm just not sure how to do this.

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

I tried using ..

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

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

Any ideas?

+4
source share
1 answer

Does it help? I tested the application from which it was, and it successfully posted my update using diacritics in your message (and 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(); 
+1
source

Source: https://habr.com/ru/post/1302077/


All Articles