Little Fox
Little Fox

Reputation: 1252

How to send an emoji?

How can I post an emoji? If I place it in url instead of +message+ I will get wrong url, because sign "&" makes url invalid and my message won't be send.

 string url = "https://api.vk.com/method/messages.send?user_id=" + user_id + "&message=" + message + "&v=5.31&access_token=...";

♥ - &#9829

Upvotes: 3

Views: 1467

Answers (1)

Bas
Bas

Reputation: 27105

URL Encode you message by calling HttpUtility.UrlEncode (link):

string message = "&#9829";
message = HttpUtility.UrlEncode(message);
Console.WriteLine(message); // outputs %26%239829

This will cause your data to never make the URL invalid, but still be readable as &#9829 at the destination. You may have to reference System.Web in your project.

Upvotes: 2

Related Questions