close

[Solved] Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.

Hello Guys How are you all? Hope You all are fine. When I was trying to run my flutter app and suddenly I get the following error in my stack track. Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error in a flutter. So today Here I come with all possible solutions for this error.

We are providing you all possible solutions to solve this error. let’s start this article without wasting your time.

How Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest Error Occurs ?

I am trying to hit an API endpoint from a Flutter web application, every time it errors out and gives me the following error.

Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.

How to Solve Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.?

  1. How to Solve Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error.?

    To Solve Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error Server is blocking your request so you have to put this line at your sites-enabled config file.

  2. Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest

    To Solve Error getting sensor data: DioError [DioErrorType.RESPONSE]: XMLHttpRequest error Server is blocking your request so you have to put this line at your sites-enabled config file.

Solution 1

I just Fixed By below code

return {
    statusCode: 200,
     headers: {
  "Access-Control-Allow-Origin": "*", // Required for CORS support to work
  "Access-Control-Allow-Credentials": true, // Required for cookies, authorization headers with HTTPS
  "Access-Control-Allow-Headers": "Origin,Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token,locale",
  "Access-Control-Allow-Methods": "POST, OPTIONS"
},
    body: JSON.stringify(item)
};

Solution 2

Server is blocking your request so you have to put this line at your sites-enabled config file.

add_header Access-Control-Allow-Origin "*";
add_header Access-Control-Allow-Methods "GET, HEAD";

Summery

So, It’s All About This Error. I hope this tutorial helps you to Solve your error. Please Comment Below if You stucks anywhere with my code. And please comment below on which solution worked for you. Thank You.

Also Check Out Below Tutorials

Leave a Comment

%d bloggers like this: