API calls error "Content Security Policy Upgrading insecure request"

Solved
Ajay_Singh1
Tourist
12 0 1

I'm calling API request to get geo location based on users IP with the code below.

Resulting response is that my account at the service provider does not have access to https.

I can see from the browser log that the request is changed to https :

Content Security Policy: Upgrading insecure request ‘http://api.ipstack.com/check?access_key=KEY&fields=country_code&callback=jQuery1113020230380784044855_1612254715210&_=1612254715211’ to use ‘https’

Please advice how to keep the http request to stay as http request, without this automatic upgrading to https.

The code is the following:

$.ajax({
  	url: 'http://api.ipstack.com/check?access_key=KEY=country_code',   
    dataType: 'jsonp',
    success: function(location) {    
      
    if (location.country_code === 'US') 
    {      
      window.location.replace("https://www.google.com");
    } 
    else 
    {
      
    }
   }
} );  

 

0 Likes
tim
Shopify Expert
2857 117 937

This is an accepted solution.

You can't. Buy  paid access at ipstack.com -- guess why do they offer free access only via HTTP?

Or move to https://freegeoip.app/ 

Want to hire me to tweak a theme? Mail me at tairli@yahoo.com!
My post solved your problem? Like it!