我尝试像这样在我的React应用中使用superagent调用api:
import superagentPromise from 'superagent-promise';
import _superagent from 'superagent';
import { Base64 } from 'js-base64';
const API_ROOT = 'https//myapiurl.com/api';
const superagent = superagentPromise(_superagent, global.Promise);
login: (username, password) => {
let encrypt = Base64.encode(`${username}:${password}`);
return superagent.get(`${API_ROOT}/initSession`)
.use(tokenPlugin).set('Authorization', `Basic ${encrypt}`)
.then(responseBody)
}
但有任何通话,请在我的通话中添加'http://localhost:8001',在chrome调试中,我得到了“ Request URL http://localhost:8001/https//myapiurl.com/api/initSession'
我什么都不知道,两天后我正在寻找解决方案...
先谢谢。