Quantcast
Viewing all articles
Browse latest Browse all 1589

(Tauri) API request with ignoring the SSL certificate (https)

I creating a Tauri app that makes a request via https protocol to the controller with required SSL certificate.Now I can ignore the certificate, but in the future I will need to support it and be able to add it.

I using Tauri with Vite.

I'm moving from Electron to Tauri and previously I used Axios to ignore the certificate I used https agent but I don't know how to use it in Tauri.

I tried several solutions:

  1. Tauri http module
import { getClient } from '@tauri-apps/api/http'; const client = await getClient(); const response = await client.delete('https://192.168.100.100/');

It throws an error: Uncaught (in promise) Network Error: Tls Error I suspected an error because it's an http module, not https.

  1. Tauri axios adapter
import axios from 'axios';import axiosTauriAdapter from 'axios-tauri-adapter';const client = axios.create({ adapter: axiosTauriAdapter });document.getElementById("get-ata").addEventListener("click", api_get_ata)function  api_get_ata(){    axios.get("https://192.168.100.100/")    .then(function (response){        console.log(response)    })    .catch(function (error) {        console.log("Error: ", error);    });}

It also throws the error: GET https://192.168.100.100/ net::ERR_CERT_AUTHORITY_INVALIDand there is a similar error from Axios.I tried adding option to axios that ignore the certificate, but it doesn't do anything.

  1. Rust backend
#[tauri::command]fn api_post_req(url: &str, auth: &str, body: String, timeout: f32) -> String{   let client = Client::builder()    .danger_accept_invalid_certs(true)    .build()    .unwrap();  let time: Duration = Duration::from_secs_f32(timeout);  let result = client    .post(url)    .header("authorization", auth)    .body(body)    .timeout(time)    .send();  return convert_response(result)}fn convert_response(result: Result<Response, Error>) -> String {  return match result {    Ok(response) => {      match response.text() {        Ok(text) => {          text        }        Err(err) => {"Something messed up! but result was ok. Rust error:".to_string() + err.to_string().as_str()        }      }    },    Err(error) => {"Rust error: ".to_string() + error.to_string().as_str()    }  }}

It works but it isn't async and when I make a request every 300ms, the whole application freezes. I am not a Rust guy and I don't want write in it, to make it async.

I looking for a better solution


Viewing all articles
Browse latest Browse all 1589


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>