Can we run https calls in canister with ip address directly?

// 
#[ic_cdk::update]
pub async fn get_payload_from_my_server(
) -> String {
  let url = "https://1.2.3.4:8002/file/file/ret_to_res_body/payload_02.json";
  let request = CanisterHttpRequestArgument {
    url: url.to_string(),
    max_response_bytes: None, //optional for request
    method: HttpMethod::POST,
    headers: Vec::new(),
    body: None,
    transform: None, //optional for request
  };

  let cycles = 1 * TERA;

  match http_request(request, cycles).await {
    Ok((response,)) => {
      let mut str_body = String::from_utf8(response.body)
        .expect("Transformed response is not UTF-8 encoded.");
      str_body = str_body.replace("\\", "");
      str_body
    }
    Err((r, m)) => {
      let message =
      format!("The http_request resulted into error. RejectionCode: {r:?}, Error: {m}");
      message
    }
  }
}

dfx canister call backend get_payload_from_my_server

return:

“The http_request resulted into error. RejectionCode: SysTransient, Error: Connecting to 1.2.3.4 failed: Request failed direct connect error trying to connect: invalid peer certificate: UnknownIssuer and connect through socks error trying to connect: dns error: failed to lookup address information: Name or service not known”,

Given that IPv6 is required for HTTP outcalls, I would guess that’s why it fails with 1.2.3.4. However, based on your stack trace, it also seems the SSL certificate is not recognized for your call.

Yes. i use self ssl certification:

this cmd can get respon.body data :
wget -v -O- https://<a_ip_v4_addr>:8002/file/file/ret_to_res_body/
payload_02.json --no-check-certificate

allright. i will try to get a ipv6 addr firstly

The higher problem is that i actually want to send a file to my rust canister on ic.
Only get this solution yet. If there is any better way will be great.

Don’t know about your use case, just wanted to shared the above information given it seemed related to the error you were facing.

Solved by learning this code hah.

1 Like

Gotcha. Funny enough it’s the same approach I had to implement in my “Juno <> OpenAI” demo to pass a file to the Vision Preview API.

Great to hear you solved it!

1 Like