Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialAlex Franklin
12,403 Pointsastronauts in space receiving mixed content error because everything is HTTPS now and the endpoint is HTTP... HELP?!
callbacks.js:16 Mixed Content: The page at 'https://codepen.io/' was loaded over HTTPS, but requested an insecure XMLHttpRequest endpoint 'http://api.open-notify.org/astros.json'. This request has been blocked; the content must be served over HTTPS.
I am getting the above error - can someone please help me with whatever the work around is for this?
2 Answers
Steven Parker
231,271 PointsTry changing the URL of the request to use https instead of http. The server you are contacting will most likely allow both kinds of requests.
Alex Franklin
12,403 PointsThank you, Steven. At least I know now that it wasn't just ME! I think this is a good example of when proficiency in a back end language might come in handy for me, like it mentions in the lesson, to have the exchange occur between servers and avoid CORS restrictions altogether!
Alex Franklin
12,403 PointsAlex Franklin
12,403 PointsI did try that and didn't have any luck...
The other two things I tried were to leave it off completely, like only have a relative url,("//api.open-notify.org/astros.json"),...
and to add a header to my request for "Access-Control-Allow-Origin", "*".
are there any other things I can do to try and make this work?
here is a link to a codepen i'm using to try and find a fix:
https://codepen.io/alex-franklin/live/LKodaY
THIS DOES WORK IF I AM IN A LOCAL CODING ENVIRONMENT, LIKE VS CODE, BUT I CAN'T GET IT TO WORK ANYWHERE ELSE...
AND THANK YOU FOR YOUR RESPONSE AND HELP!
Steven Parker
231,271 PointsSteven Parker
231,271 PointsI tried connecting directly to the URL ("https://api.open-notify.org/astros.json") from my browser, and the connection was refused. Perhaps that server just doesn't accept https protocol requests.
You'll probably need a proxy or run your code from a server you can connect to using http.
Isn't CORS fun?