0

while requesting data from server using Axios.post("http://localhost:5000/api/admin/getdblogo") from another device in same network , it gives the follwing error:-

Google chrome error

xhr.js:220 POST http://localhost:5000/api/admin/getdblogo net::ERR_CONNECTION_REFUSED

Morzilla firefox error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:5000/api/admin/getdblogo. (Reason: CORS request did not succeed). Status code: (null).

what have been tried out:

in the server this line is added:

const cors = require('cors');
app.use(cors({origin:'http://localhost:3000'}));

in the client side the request that is causing the error is :

const [Logo,setLogo] = useState(null);
const GetLogo = async() => {

    const response = await Axios.post("http://localhost:5000/api/admin/getdblogo");

    if (response.data.recordset.length === 0) {

        setLogo(null);

    }
    else if (response.data.recordset.length === 1) {
        console.log(response);
        const imagedata = await btoa(String.fromCharCode(...new Uint8Array(response.data.recordset[0].PICTURE.data)));

        setLogo(imagedata);

    }

}
2
  • did you test with postman to see if the API works? Commented Aug 29, 2022 at 10:12
  • because the code looks fine. If you are using it properly and haven't done any silly syntax error it should work correctly. Commented Aug 29, 2022 at 10:12

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.