我试图通过以下语法使用访存:
fetch("https://user:password@url", {
...
}).then((response) => {
...
}).done();
相同的URL在CURL中有效,但在React Native中返回401。
有任何想法吗?
谢谢保罗
我发现这种格式https://user:password@url
在CURL和节点中效果很好,但在fetch中效果不佳。
我必须使用base-64
npm模块并通过Headers对象。
// https://www.npmjs.com/package/base-64
const base64 = require('base-64');
...
var headers = new Headers();
headers.append("Authorization", "Basic " + base64.encode("user:password"));
fetch("https://url", {
headers: headers
})
.then((response) => { ... })
.done();
`
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句