0

I have a unique edge case. I am building a hybrid app, and using axios to send commands to an IOT device.

The problem is the IOT device is not supporting the OPTIONS header. If I send a plain axios.post, I can see a response in the network tab. But if I put in async/await function the request hangs in pending, I assume because its waiting for response to options.

I double the JS itself is helpful, but I include it for good measure: This works:

const auth = { username: 'admin', password: 'rLVeWja2zf' }
 axios.post('http://192.168.4.1/cmd', { "cmd": "{\"cmd\": {\"uuid\": \"0861F\", \"value\": \"1fa4ffd118219f4ed1bcb27ef8e5e71d\"}}" }, { auth} )

this doesn't:

const init = async() => {
     const auth = { username: 'admin', password: 'rLVeWja2zf' }
     axios.post('http://192.168.4.1/cmd', { "cmd": "{\"cmd\": {\"uuid\": \"0861F\", \"value\": \"1fa4ffd118219f4ed1bcb27ef8e5e71d\"}}" }, { auth} )

 .then(response => {
 const users = response.data.data;
 console.log(`GET list users`, users);
 })
 .catch(error => console.error(error));
 };
 
 init();
TDawg
  • 753
  • 1
  • 6
  • 21
  • 1
    "The problem is the IOT device is not supporting the OPTIONS header." — If you can't persuade the IOT device to conform to the CORS spec and grant permission to your client-side code to read data from it, then you can't use client-side code to read data from it. Use server-side code instead. – Quentin Jun 18 '21 at 07:33

0 Answers0