Sending special characters
See original GitHub issueI would like to send a String containing special characters "ä ö ü ß 😀"
Before doing anything complex, I tried
TelegramBot bot = new TelegramBot(System.getenv("TELEGRAM_BOT_TOKEN"));
SendResponse response = bot.execute(new SendMessage(1076643869, "ä ö ü ß 😀"));
System.out.println(response.message().text());
from which I receive a message containing ä ö ü ß 😀
and ä ö ü ß 😀
in the console.
I suspect that there is no fundamental error in my charset, since sending a HTTP POST request manually does not produce the error:
OutputStreamWriter writer = null;
BufferedReader reader = null;
try {
URL url = new URL("https://api.telegram.org/bot" + System.getenv("TELEGRAM_BOT_TOKEN") + "/sendMessage");
String payload = "{\"chat_id\": 1076643869, \"text\": \"ä ö ü ß 😀\"}";
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoInput(true);
con.setDoOutput(true);
con.setUseCaches(false);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Content-Length", String.valueOf(payload.length()));
writer = new OutputStreamWriter(con.getOutputStream());
writer.write(payload);
writer.flush();
reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
StringBuilder builder = new StringBuilder();
for (String line; (line = reader.readLine()) != null; ) {
builder.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (writer != null)
writer.close();
if(reader != null)
reader.close();
} catch (IOException e) {
System.err.format("Cant close writer or reader: %s%n", e);
}
}
sending a message containing ä ö ü ß 😀
Thanks to pengrad’s quick reply to my email, I could figure out that I am using the default windows charset;
System.out.println(System.getProperty("file.encoding")); // Prints windows-1252
System.out.println(Charset.defaultCharset().name()); // Prints windows-1252
A stated above, I don’t think that changing the charset via the VM options would fix the issue, although pengrad stated that it works fine for him (at least using “ä, ö, ü and ß”)
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Sending Special Characters - Payment API - Ratepay
There are some special characters that are used by the XML syntax. If used within elements and attributes they needed to be escaped...
Read more >Using special characters, Unicode, and GSM-T charsets for ...
Using special characters, Unicode, and GSM-T charsets for sending SMS in different languages ... SMS can be sent out using different charsets or ......
Read more >Special characters supported in email - Acoustic Help Center
Some special characters, such as hearts, spades, diamonds, and copyright symbols, display in emails, but only if these are within the defined ...
Read more >Sending special characters using HttpURLConnection in Java
I have a web service and I want to invoke that with "application/x-www-form-urlencoded" content type. The request sometimes contains special ...
Read more >send special characters - the Tcler's Wiki!
Stefan Finzel. Now and then there is the need to handle special characters like CTRL-C e.g. to send special command sequences to devices...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Unfortunately, I did not. To be honest, I have no clue what to do other than manually overwriting, thus changing the library used to execute the request…
Please add encoding UTF-8