我正在寻找解决这个问题的方法。我想将 prestashop REST API 用于特定的测试活动。我的问题是我无法使用此表单进行身份验证,甚至无法使用缓冲区和 DOMParser,因为我正在为 android 4.4.1 开发一个项目并且缓冲区不兼容。
有人可以帮忙吗?先感谢您。此致。
我做了这样的事情(下面两个例子):
let API = null;
const SERVER_ADDRESS = 'http://192.168.1.5/prestashop/api/';
//也尝试了“&output_format=JSON” const token = 'X3IIMEP8JJI3PKPXIMEP8JJI3PKPICJMM';
try {
fetch(SERVER_ADDRESS, {
method: 'GET',
headers: {
'Authorization': token
}
})
.then(function(response) {
if(response.status == 200) return response.json();
else throw new Error('Something went wrong on api server!');
})
.then(function(response) {
console.debug(response);
// ...
})
} catch (e) {
alert(e);
}
=========================
import {Buffer} from 'buffer';
import {DOMParser} from 'xmldom';
let API = null;
const SERVER_ADDRESS = 'http://192.168.1.5/prestashop/api/';
const REST = {
CMS: 'content_management_system'
};
const token = 'XGRCBUW745EH4SPHCU92MKL4RGNVPYXY';
const AuthorizationString = 'Basic ' + new Buffer(token + ':').toString('Base64');
try {
componentDidMount({
fetch(SERVER_ADDRESS, {
method: 'GET',
headers: {
'Authorization': AuthorizationString
}
}).then(function (response) {
response.text().then(function (text) {
API = new DOMParser().parseFromString(text);
});
});
}
}
catch (e) {
alert(e);
}