I have a Java GRPC endpoint and I want to call it from a RUST client. If I use postman I get the response. Everything is fine.
Postman call
When I try to do it from rust, I get the error:
Error: tonic::transport::Error(Transport, hyper::Error(Connect, ConnectError("tcp connect error", Os { code: 111, kind: ConnectionRefused, message: "Connection refused" })))
Code:
use todo::todo_client::TodoClient;
use todo::{CreateTodoRequest};
pub mod todo {
tonic::include_proto!("todo");
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut client = TodoClient::connect("http://0.0.0.0:50052").await?;
let create_request = tonic::Request::new(CreateTodoRequest {
username: "username".to_string(),
password: "password".to_string(),
});
let create_response = client.authenticate(create_request).await?;
println!("{:?}", create_response.into_inner());
Ok(())
}
I tried change the URL to "localhost", with and without http://, didn't work. Im using the same proto file:
syntax = "proto3";
package todo;
message CreateTodoRequest {
string username = 1;
string password = 2;
}
message CreateTodoResponse {
int32 expiresIn = 1;
string accessToken = 2;
string refreshToken =3;
string idToken = 4;
}
service Todo {
rpc authenticate(CreateTodoRequest ) returns (CreateTodoResponse );
}