API 需要设置 user-agent 但它在 chrome 中是不安全的 header
API requires a user-agent to be set but its a unsafe header in chrome
我一直在尝试从 Shoppy API 请求信息,我在 chrome 和 opera 上得到的回复是这样的
在 Shoppy API 文档中,它说需要设置一个 user-agent,根据我查看堆栈溢出帖子的理解,这是不可能的。但是,我想知道的问题是是否有解决方法?
旁注:使用 Firefox,我成功地从 API 获得了启用了 CORS 扩展的响应。
mounted () {
axios
.get('https://shoppy.gg/api/v1/products/', {
headers: {
'Authorization': 'placeholder',
'Access-Control-Allow-Origin': 'https://shoppy.gg',
useCredentails: true, 'user-agent': 'Shoppy'}})
.then(res => console.log(res))
.catch(err => console.log(err));
// .then(response => (this.info = response))
}
如果您从非浏览器客户端应用程序使用他们的API,您只需要担心设置用户代理。如果您通过浏览器在网站上使用他们的API,那么将自动使用浏览器的用户代理,您无需执行任何操作。
我一直在尝试从 Shoppy API 请求信息,我在 chrome 和 opera 上得到的回复是这样的
在 Shoppy API 文档中,它说需要设置一个 user-agent,根据我查看堆栈溢出帖子的理解,这是不可能的。但是,我想知道的问题是是否有解决方法?
旁注:使用 Firefox,我成功地从 API 获得了启用了 CORS 扩展的响应。
mounted () {
axios
.get('https://shoppy.gg/api/v1/products/', {
headers: {
'Authorization': 'placeholder',
'Access-Control-Allow-Origin': 'https://shoppy.gg',
useCredentails: true, 'user-agent': 'Shoppy'}})
.then(res => console.log(res))
.catch(err => console.log(err));
// .then(response => (this.info = response))
}
如果您从非浏览器客户端应用程序使用他们的API,您只需要担心设置用户代理。如果您通过浏览器在网站上使用他们的API,那么将自动使用浏览器的用户代理,您无需执行任何操作。