Strict-origin-when-cross-origin cors

Hello ,
i am using the data API and getting strict-origin-when-cross-origin issue (cors).
I am using to fetch data by java script. I am attaching the file of error.

code is using to fetch data and same code working for postman

Please provide solution for this ASAP.

Thanks
Puneet

Hi @Puneet_singh2 and welcome to the community forum.

It seems you might have to enable the cors support in your Java application.
If you are using a spring application, you might want to configure using addCorsMappings to add cors mapping to your application.

If this is already enabled, could you please help me with the server and the spring boot version you are using?

Please do not hesitate to reach out in case of further questions.

Regards
Aasawari

@Aasawari I am not using java code here.
here is just JS and HTML file .

I am sharing code here

i am uploading the both code file JS +Html . [quote=“Puneet_singh2, post:1, topic:277977, full:true”]
Hello ,
i am using the data API and getting strict-origin-when-cross-origin issue (cors).
I am using to fetch data by java script. I am attaching the file of error.

code is using to fetch data and same code working for postman

Please provide solution for this ASAP.

Thanks
Puneet
[/quote]

function getData() {
    SubscriptionKey="R3TwNJeS23g0lKD08Gb6jx3RfYI3isHuEg7VmxSeBiGiHCtNPObUWwHF3lkH7T00";

    let req = new XMLHttpRequest();
    let url = "https://ap-south-1.aws.data.mongodb-api.com/app/data-ohrsdji/endpoint/data/v1/action/findOne";

    var params = JSON.stringify(
        {
            "collection":"users",
            "database":"test",
            "dataSource":"TestDB",
            "projection": {"_id": 1}
        }
    )
    req.open("POST", url , true);
     req.setRequestHeader('api-key', SubscriptionKey);
  req.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
  req.setRequestHeader('Access-Control-Request-Headers', '*' );
  //req.setRequestHeader('Authorization', 'Bearer R3TwNJeS23g0lKD08Gb6jx3RfYI3isHuEg7VmxSeBiGiHCtNPObUWwHF3lkH7T00');

    req.onreadystatechange = function () {
      if (req.readyState == 4) {
        if (req.status == 200){
         console.log(req);
        }else{
            console.log(req);
        }
      }
    };
    req.send(params);
    
}

Below are html code

<!DOCTYPE html>
<html>
<head> <script src="./app.js" type="text/javascript"></script></head>

<body onload="getData()">

<h1>My First Heading</h1>
<p>My first paragraph.</p>

</body>
</html>
 

Please provide solution asap