Posts: 16
Joined: May 2011
Reputation:
0
Hi I'm new to C# and trying to add a http post to scan the library. It works as it should on Kodi but i get an"connection was closed" in c#. Anyone who can guide me in the correct way?
Thanks
Posts: 19,982
Joined: May 2009
Reputation:
451
nickr
Retired Team-Kodi Member
Posts: 19,982
Hard to tell without your code. Not that I am a c# user, but someone may be. Alternatively some c# forum which may help you with a json call.
If I have helped you or increased your knowledge, click the 'thumbs up' button to give thanks :) (People with less than 20 posts won't see the "thumbs up" button.)
Posts: 16
Joined: May 2011
Reputation:
0
2016-08-16, 11:38
(This post was last modified: 2016-08-17, 11:39 by ludwich.)
this code sends it to the player and it updates but as i said the connection closes and that gives the error in the C# software. Have been looking at C# forums but nobody seems to have this problem thats why im in the kodi forum =)
string kodiIp = "192.168.1.10";
string port = "9002";
string httpBase = "http://"+kodiIp+":"+port+"/jsonrpc?request=";
JsonSerialize test = new JsonSerialize();
test.jsonrpc = "2.0";
test.method = "VideoLibrary.Scan";
string json = JsonConvert.SerializeObject(test);
using (var webClient = new WebClient())
{
var response = webClient.UploadString(httpBase, "POST", json);
}
FIXED .
string kodiIp = "localhost";
string port = "9002";
string httpBase = "http://" + kodiIp + ":" + port + "/jsonrpc?request=";
JsonSerialize test = new JsonSerialize();
test.jsonrpc = "2.0";
test.method = "VideoLibrary.Scan";
test.id = 1;
string json = JsonConvert.SerializeObject(test);
Console.WriteLine(httpBase + json);
using (var webClient = new WebClient())
{
webClient.Headers.Set("Content-Type", "application/json");
var response = webClient.UploadString(httpBase, "POST", json);
webClient.Dispose();
}
was missing the id property in the test object.