Seeking some help on the following:
Why does the following work and return a 200 (setting an event)
$.ajax({url : 'https://www.eventbriteapi.com/v3/events/?token=<MYTOKEN>&event.name.html=bob%20smith&event.start.utc=2015-12-13T10:39:35Z&event.start.timezone=Europe/London&event.end.utc=2015-12-13T10:39:35Z&event.currency=GBP&event.end.timezone=Europe/London', type: 'POST', data : {}})
When the following node POST does not?
// post data
var post_options = {
host: 'https://www.eventbriteapi.com',
port: 80,
path: '/v3/events/?token=<TOKEN>&event.name.html='+ encodeURIComponent(name) +'&event.start.utc=2015-12-13T10:39:35Z&event.start.timezone=Europe/London&event.end.utc=2015-12-13T10:39:35Z&event.currency='+ encodeURIComponent(currency) +'&event.end.timezone=Europe/London',
method: 'POST',
headers: { "Content-type": "application/x-www-form-urlencoded" }
};
var httpreq = http.request(post_options, function (response) {
console.log(response);
//response.writeHead(200, {'Content-Type': 'text/plain; charset=utf8'});
response.on('data', function(chunk) {
console.log('%s', chunk);
});
response.on('end', function () {
res.send('ok')
});
});
The response is a 403 yet logging what was actually sent in the Node POST is identical to the AJAX call:
method: 'POST',
path: '/v3/events/?token=<MYTOKEN>&event.name.html=bob%20smith&event.start.utc=2015-12-13T10:39:35Z&event.start.timezone=Europe/London&event.end.utc=2015-12-13T10:39:35Z&event.currency=gbp&event.end.timezone=Europe/London'
Try out the node module request (npm install request
). It makes HTTP requests significantly easier to deal with:
var request = require('request');
request.post({
url: "http://my_url.com",
form: {
key: "value" // post data goes here
}
}, function(error, response, body) {
// body contains your data
});