Skip to content Skip to sidebar Skip to footer

Problem With Cors Policy, When Making A Request To Https://newsapi.org

I have been running news api on my website and testing in on my computer by dragging the file into the web browser, the url would show up like that file:///C:. Then I would upload

Solution 1:

You need a CORS proxy

const proxyUrl = "https://cors-anywhere.herokuapp.com/"const qInTitle = "";
constfrom = "";
const apiKey = "";
const url = `${proxyUrl}https://newsapi.org/v2/everything?qInTitle=${qInTitle}&from=${from}language=en&apiKey=${apiKey}`;
const request = newRequest(url);

fetch(request)
  .then(response => response.json())
  .then((news) => {
    console.log(news);
  })
  .catch(error => {
    console.log(error);
  });

Solution 2:

This is something that needs to be configured by https://newsapi.org. It is their site, and with CORS they communicate how and which sites are allowed to embed their content. And most modern browsers follow those restrictions.

You best bet is to contact their support, or look at account settings, maybe you need to use some token or list your site somewhere.

Other than contacting https://newsapi.org and asking them for a licence / CORS change, i guess you could do a proxy server that duplicated their content, but that probably would break the terms of use.

Post a Comment for "Problem With Cors Policy, When Making A Request To Https://newsapi.org"