//
#[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.
opened 12:49PM - 18 Mar 24 UTC
closed 12:59PM - 18 Mar 24 UTC
I searched for source code but not found out.
Its a very useful function in ca… nister !
![image](https://github.com/open-chat-labs/open-chat/assets/32679742/fe7a6057-b280-4eb2-8505-2514b4b95840)
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.
#[on_delete_many_docs]
async fn on_delete_many_docs(_context: OnDeleteManyDocsContext) -> Result<(), String> {
Ok(())
}
#[on_upload_asset(collections = ["sketches"])]
async fn on_upload_asset(context: OnUploadAssetContext) -> Result<(), String> {
// Example localhost: http://jx5yt-yyaaa-aaaal-abzbq-cai.localhost:5987/images/carbon.png
// Example mainnet: https://xo2hm-lqaaa-aaaal-ab3oa-cai.icp0.io/images/house123.png
let download_url = format!(
"https://{}.icp0.io{}?token={}",
id().to_text(),
context.data.key.full_path,
context.data.key.token.unwrap_or("".to_string())
);
let doc_key = context.data.key.full_path.clone();
let request = get_request_vision_preview(&context.data.key.name, &download_url)?;
Great to hear you solved it!
1 Like