Oyatel / CometD.NET

CometD.NET is a C# client library for the Bayeux protocol
43 stars 34 forks source link

Publish data problem with special chars #27

Closed osmanarslantas closed 2 years ago

osmanarslantas commented 3 years ago

I try publish data with following belows. But if there is a Turkish chars(like ı,ç,ş,ğ,İ) and special chars (like +,%,!), publish is not working. How i publish this chars? Please help.

Dictionary<string, object> data = new Dictionary<string, object>(); data.Add("operation", "sendMessage"); data.Add("message", "ış%ç!+ğİ");
data.Add("secureKey", "secureKey");

channel.publish(data);

osmanarslantas commented 2 years ago

I replaced in GetRequestStreamCallback method. (LongPollingTransport.cs row 203)

Current code:

// End the operation
using (Stream postStream = exchange.request.EndGetRequestStream(asynchronousResult))
{
   // Convert the string into a byte array.
   byte[] byteArray = Encoding.UTF8.GetBytes(exchange.content);
   //Console.WriteLine("Sending message(s): {0}", exchange.content);

   // Write to the request stream.
   postStream.Write(byteArray, 0, exchange.content.Length);
   postStream.Close();
}

New code:

// End the operation
using (Stream postStream = exchange.request.EndGetRequestStream(asynchronousResult))
{
   // Convert the string into a byte array.
   byte[] byteArray = Encoding.UTF8.GetBytes(exchange.content);
   //Console.WriteLine("Sending message(s): {0}", exchange.content);

   // Write to the request stream.
   postStream.Write(byteArray, 0, byteArray.Length);
   postStream.Close();
}

This working fine with me.