我使用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