Making a JSON-RPC HTTP call using C #

I would like to know how to make the next HTTP call using C #.

http://user:pass@localhost:8080/jsonrpc?request={"jsonrpc":"2.0","method":"VideoLibrary.Scan"}

When I insert this url directly into my browser (and replace the user credentials and server location), it works as expected (my XBMC video edition is being updated). This applies specifically to the HTTP methods on this page:

http://wiki.xbmc.org/index.php?title=HOW-TO:Remotely_update_library

I would like to know how to make this same successful call over HTTP using C #.

+4
source share
2 answers

Use this:

using (var webClient = new WebClient())
{
    var response = webClient.UploadString("http://user:pass@localhost:8080/jsonrpc", "POST", json);
}
+3
source

@Ganesh

HTTP 401 Unauthorized, ( http://username:password@server:port, )

using (var webClient = new WebClient())
{
  // Required to prevent HTTP 401: Unauthorized messages
  webClient.Credentials = new NetworkCredential(username, password);
  // API Doc: http://kodi.wiki/view/JSON-RPC_API/v6
  var json = "{\"jsonrpc\":\"2.0\",\"method\":\"GUI.ShowNotification\",\"params\":{\"title\":\"This is the title of the message\",\"message\":\"This is the body of the message\"},\"id\":1}";
  response = webClient.UploadString($"http://{server}:{port}/jsonrpc", "POST", json);
}
0

Source: https://habr.com/ru/post/1531662/


All Articles