User Tools

Site Tools


userspace:webservice_corner:rust-rpc

This script uses reqwest. Add the following to your `Cargo.toml`:

[dependencies]
reqwest = "0.9.9"

The main.rs looks like this:

  extern crate reqwest;
  
  use std::collections::HashMap;
  
  fn main() -> Result<(), Box<std::error::Error>> {
      let mut jrpc = HashMap::new();
      jrpc.insert("id", "1");
      jrpc.insert("method", "backend_info");
      jrpc.insert("params", "");
      
      let client = reqwest::Client::new();
      let mut response = client.post("https://YOURSERVER.NAME.TLD:4447/rpc")
          .basic_auth("YOUR_USERNAME_HERE", Some("PASSW0RDZ_HERE"))
          .json(&jrpc)
          .send()?;
      println!("Headers: {:#?}", response);
      
      let content = response.text()?;
      println!("Body: {:#?}", content);
      
      Ok(())
  }
userspace/webservice_corner/rust-rpc.txt · Last modified: 2021/08/23 08:37 (external edit)