使用 POSTMAN ,一切都很好:
我将相同的标头、参数...传递给 superagent,如下所示:
const superagent = require('superagent');
const grab = require('ps-grab');
superagent.get('https://x.rathath.net/issue_statuses.json')
.set({
'Accept': 'application/json',
'Content-Type': 'application/json'
})
.auth(grab('--user'),grab('--password'))
.send({})
.end((error,response)=>{
console.log(response.text);
});
然而失败了!
我有疑问:superagent+Authorization Header+ OSX ..我的意思是这三个的兼容性。
事实上,我在 Redhat 机器上运行相同的 javascript 片段,它工作得很好。
不同之处在于,您可能正在调用 js 应用程序运行所在的另一个域。这称为 CORS。当您这样做时,结合身份验证,服务器需要返回 CORS 标头,表示:
access-control-allow-credentials: true
access-control-allow-origin: your-app-domain.here
两个陷阱:
- 在您的超级代理调用中忘记 .withCredentials() 。这不仅适用于 cookie,也适用于身份验证。
- 服务器返回 * 而不是您的域,但不允许与身份验证结合使用。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)