Closed tanhaipeng closed 5 years ago
@KodrAus Please see this issue, thanks
I got it working using this code!:
let mut builder = SyncClientBuilder::new().static_node(es_host);
let credentials = "<Base64 encoded: username:password>"
let parameter = PreRequestParams::new();
let header = AUTHORIZATION;
let value = HeaderValue::from_str(format!("Basic {}", credentials).as_str())?;
let parameter = parameter.header(header, value);
let builder - builder.params(parameter);
let client = match builder.build() {
Err(x) => panic!("Error: {}", x),
Ok(client) => client,
};
Hope that helps :) And let's give @KodrAus a bit of slack :) He's already working so hard on this project after all!
I got it working using this code!:
let mut builder = SyncClientBuilder::new().static_node(es_host); let credentials = "<Base64 encoded: username:password>" let parameter = PreRequestParams::new(); let header = AUTHORIZATION; let value = HeaderValue::from_str(format!("Basic {}", credentials).as_str())?; let parameter = parameter.header(header, value); let builder - builder.params(parameter); let client = match builder.build() { Err(x) => panic!("Error: {}", x), Ok(client) => client, };
Hope that helps :) And let's give @KodrAus a bit of slack :) He's already working so hard on this project after all!
good! Thank you very much!
As of: #401 (6ed243570bb64fdf398cafe0518c5d9a02321c76) you can now do:
use elastic::client::SyncClientBuilder;
fn main() -> Result<(), Box<dyn std::error::Error>> {
let http_client = reqwest::Client::builder()
.danger_accept_invalid_certs(true)
.build()?;
let client = SyncClientBuilder::new()
.static_node("https://localhost:9201")
.http_client(http_client)
.params_fluent(|p| p.basic_auth("admin", Some("admin")).unwrap())
.build()?;
println!("{:#?}", client.ping().send()?);
Ok(())
}
I use basic auth to build client, but find auth is not working( username & password is correct), my code is:
Error is:
next_error: Some(Parse(ParseError { inner: UnknownApiError({"reason": String("Invalid username and password!")
Please help me!