【发布时间】:2019-04-07 14:49:43
【问题描述】:
我通过 Postman 成功触发了 POST 请求以检索 mobileSession 密钥。但是当我从 React Native 应用程序(通过 Axios)尝试相同的操作时,我得到了一些参数丢失的错误。有人可以根据 Postman 的要求告诉我 Axios 有什么问题吗?
邮递员:
和axios代码:
export function getMobileSession() {
let requestOptions = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
};
let body = {
username: 'myusername',
password: 'mypw',
api_key: 'apikey',
api_sig: 'signature',
method: 'auth.getMobileSession',
format: 'json'
};
return axios.post('Lastfm_API_URL', JSON.stringify(body), requestOptions)
.then(response => {
return response;
})
.catch(err => {
throw err;
});
}
【问题讨论】:
标签: react-native post parameters axios urlencode