我正在使用http.post node.js发布到https://api.mmitnetwork.com/Token以获取访问令牌。
如何接受我的回复并设定状态?
var App = React.createClass ({
getInitialState() {
return {
token: ''
}
},
componentDidMount() {
var _this = this;
var request = http.post('https://api.mmitnetwork.com/Token', {grant_type: 'password', username: 'myusername', password: 'mypassword'}, function(response) {
console.log(response.statusCode);
response.on('data', function(chunk) {
console.log('BODY: ' + chunk);
_this.setState({
token: response.chunk.access_token
})
});
})
request.on('error', function(err) {
console.error(err.message);
})
},
render() {
{this.state.token}
}