The error I am encountering in the console browser is:
Access to fetch at 'https://website.com/api/imtryingtofetchhere' from origin
'https://mywebsite.com' has been blocked by CORS policy: Response to preflight
request doesn't pass access control check: No 'Access-Control-Allow-Origin'
header is present on the requested resource. If an opaque response serves your
needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I already tried a lot of methods everything I saw marked as "correct" here in Stack OverFlow, however nothing works. I already tried method using AXIOS before using fetch and still no luck of work. API is working on website like https://reqbin.com and I am now clueless on how to fix this thing.
Things that I've tried fetch & axios and other:
- Adding/Removing allowed cross origin
- with/without certificates
- include/not include credentials
- Disabled/Enabled CORS
- Adding Head
- Tried to add origin to .htaccess and php file still no hope
I also tried both of Axios link
Using jsDelivr CDN:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
Using unpkg CDN:
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
This is working on my discord bot, but on my website it doesn't work...
JS Code from my discord bot:
const hashToMintme = await axios.get(
`https://www.coinimp.com/api/v2/payout/1mhash?currency=MINTME`,
{
headers: {
'X-API-ID': 'API ID HERE',
'X-API-KEY': 'API KEY HERE',
},
}
);
JS Code from my php website:
<script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
<script>
const axios = require('axios');
const hashToMintme = await axios.get(`https://www.coinimp.com/api/v2/payout/1mhash?currency=MINTME`, {
headers: {
'X-API-ID': 'API ID HERE',
'X-API-KEY': 'API KEY HERE'
}
});
</script>
This is the fetch code:
let headers = {
'X-API-ID': 'API ID HERE',
'X-API-KEY': 'API KEY HERE',
};
const hashToMintme = fetch(
`https://www.coinimp.com/api/v2/payout/1mhash?currency=MINTME`,
{
mode: 'cors',
credentials: 'include',
method: 'GET',
headers: headers,
}
);
I didn't include the other settings since they are useless and not working.