在任何地方使用 CORS 从我的本地本地主机到外部 URL 的 API 调用

问题描述

我正在尝试使用附加到实际 URL/端点的任何 URL 的 CORS 从我的本地本地主机到外部 URL 的 API 调用。但是,它会导致“缺少必需的请求标头”。必须指定 origin,x-requested-with' 错误之一。

//Get Qoute From API 
async function getQuote() {   
const proxyUrl = 'https://cors-anywhere.herokuapp.com/'   
const apiUrl = 'https://api.forismatic.com/api/1.0/?method=getQuote&lang=en&format=json' try {
    const response = await fetch(proxyUrl + apiUrl)
    const data = await response.jeson()
    console.log(data)   
} catch (error) {
    console.log('whoops,no quote',error)   
} 
}

// On Load 
getQuote()

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)