I am trying to read a json string from a webrequest. I use the HttpWebRequest because the server need authentication.
I can read the answer string, except the data between the [ ].
the answer should look like this:
{
"id": 1,
"jsonrpc": "2.0",
"result": [{
"playerid": 0,
"type": "video"
}]
}
but only looks like this:
{
"id": 1,
"jsonrpc": "2.0",
"result": []
}
The json is generated by Kodi/xbmc
What am I doing wrong?
static void Main(string[] args) {
string Url = @" http://192.168.1.118:8080/jsonrpc?request={""jsonrpc"": ""2.0"", ""method"": ""Player.GetActivePlayers"", ""id"": 1} ";
string credentials = "user:passwd";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Url);
request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(credentials)));
request.PreAuthenticate = true;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Stream resStream = response.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string text = reader.ReadToEnd();
Console.WriteLine(text);
Console.ReadLine();
}