Note that there are some explanatory texts on larger screens.

plurals
  1. POSpecial character encoding for Outlook calendar api
    primarykey
    data
    text
    <p>I'm trying to add an appointment with special characters like "ø" to my Outlook calendar through the live connect api. I'm trying to convert the characters to UTF-8 by using this function:</p> <pre><code>public string ConvertStringToUTF8(string str) { byte[] bytearray = Encoding.UTF8.GetBytes(str); str = Encoding.UTF8.GetString(bytearray, 0, bytearray.Length); return str; } </code></pre> <p>And then send it to Outlook with the charset set to UTF-8. But Outlook returns an error saying I don't send valid JSON... (If I don't use special characters like that it works fine)</p> <p>EDIT: request</p> <pre><code>private void MakeRequest() { // make request HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://apis.live.net/v5.0/me/events?suppress_response_codes=true&amp;suppress_redirects=true"); request.Method = "POST"; request.ContentType = "application/json;charset=UTF-8"; request.Headers["Authorization"] = "bearer " + appsettings["outlookkey"]; // start the asynchronous request request.BeginGetRequestStream(GetEventWriteCallback, request); } private void GetEventWriteCallback(IAsyncResult result) { // get the request HttpWebRequest request = (HttpWebRequest)result.AsyncState; // End the operation Stream postStream = request.EndGetRequestStream(result); // create new appointment AppointmentClass appoint = new AppointmentClass(); appoint.calendar_id = calendar_id; appoint.name = subjectstring; appoint.description = descriptionstring; appoint.availability = "busy"; appoint.is_all_day_event = allday; appoint.visibility = "public"; appoint.location = locationstring; appoint.start_time = start.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + start.ToString("zzzzz"); appoint.end_time = end.ToString("s", System.Globalization.CultureInfo.InvariantCulture) + end.ToString("zzzzz"); // generate json string from Appointment class MemoryStream stream = new MemoryStream(); DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(AppointmentClass)); ser.WriteObject(stream, appoint); stream.Position = 0; StreamReader sr = new StreamReader(stream); string payload = sr.ReadToEnd(); Debug.WriteLine("sending appointment: " + payload); // Convert the string into a byte array. byte[] byteArray = Encoding.UTF8.GetBytes(payload); // Write to the request stream. postStream.Write(byteArray, 0, payload.Length); postStream.Close(); // start the asynchronous request request.BeginGetResponse(GetEventResponseCallback, request); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload