Pixabay API HTTP redirection and Mixed Content error

387 Views Asked by At

When I fetch images from the Pixabay API:

fetch(`https://pixabay.com/api?key=${API_KEY}&per_page=7`)

I get the Mixed Content error:

Mixed Content: The page at 'https://my-page.com/' was loaded over HTTPS, but requested an insecure resource 'http://pixabay.com/api/?key=xxx&per_page=7'. This request has been blocked; the content must be served over HTTPS.

Which I don't understand, since I call https://pixabay.com from https://my-page.com. After inspecting the Network tab in the console, I see that there is 3 requests:

enter image description here

  1. The initial request that responds with a 301 Redirect to http://pixabay.com
  2. The second request http://pixabay.com that responds with a 307 Internal Redirect to https://pixabay.com
  3. Finally the last request https://pixabay.com that responds with a 200

Why all this redirects? Do I miss something obvious?
How to make the Pixabay API work properly with HTTPS?

0

There are 0 best solutions below