I am facing an issue while sending a fetch request from a nodeJS scripture react-native app or reactJs side.
I am not the same network I connected to the hotspot of Raspberry Pi 4 when I run this script of python it is working fine.
import requests
# TODO: Change the URL to your Jetson Nano IP address
url = "https://10.42.0.1:5000/wifi"
cert_path = "/Users/artemiikhristich/Desktop/TextureExtraction3/Network/certs/certificate.crt" # Update with your actual certificate path
data = {"ssid": "Blueground", "password": "Showupstartliving1"}
try:
response = requests.post(url, json=data, verify=False)
if response.status_code == 200:
print("WiFi credentials sent successfully.")
else:
print(f"Error sending WiFi credentials. Status code: {response.status_code}")
except requests.RequestException as e:
print(f"Error: {e}")
But if I run this script of Axois or Fetch it has Network Error.
const test_iCast_wifi = () => {
setMyTestLoading(true);
const myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');
const raw = JSON.stringify({
ssid: 'HUAWEI_B818_4211',
password: '4RM9LE059DG',
});
const requestOptions = {
method: 'POST',
headers: myHeaders,
body: raw,
};
fetch('https://10.42.0.1:5000/wifi', requestOptions)
.then(response => response.text())
.then(response => {
console.log(response);
setMyTestLoading(false);
Alert.alert('test_iCast_wifi SUCCESS', JSON.stringify(response));
})
.catch(error => {
console.log(error, "ERROR");
setMyTestLoading(false);
Alert.alert('test_iCast_wifi ERROR', JSON.stringify(error));
});
};