我使用Kodi API,通过asp.net控制我的htpc。特别是名为“Playlist.Add”的功能。 JSON的我送是这样的:Kodi中的非英文字符API
{"jsonrpc":"2.0","method":"Playlist.Insert","params":{"playlistid":0,"position":0,"item":{"file":"smb://server/Ferry Corsten/Beautiful/Ferry Corsten - Beautiful (Extended).mp3"}},"id":1}
这是工作的罚款。但是当这样的字符串中有一些没有英文字符时:
{"jsonrpc":"2.0","method":"Playlist.Insert","params":{"playlistid":0,"position":0,"item":{"file":"smb://server/01-Zum Geburtstag viel Glück.mp3"}},"id":1}
它只是抛出一个“RequestCanceled”异常。
我的C#源代码是这样的:
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(_url);
string authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(_username + ":" + _password));
webRequest.Headers["Authorization"] = "Basic " + authInfo;
webRequest.Method = "POST";
webRequest.UserAgent = "KodiControl";
webRequest.ContentType = "application/json";
webRequest.ContentLength = json.Length;
using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))
{
streamWriter.Write(json);
streamWriter.Flush();
streamWriter.Close();
}
唯一的例外是在streamWriter.Flush()
抛出。 所以我有什么做了这个要求?``
只是一个猜测:也许你必须用UTF-8编码请求。 – andpei