通过查询字符串发布节点失败,但在 jQuery AJAX 中没问题
Node posting via querystring fails, yet in jQuery AJAX it's fine
寻求以下方面的帮助:
为什么下面的工作和return一个200(设置一个事件)
$.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 : {}})
当下面的节点POST没有?
// 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')
});
});
响应是 403,但记录在节点 POST 中实际发送的内容与 AJAX 调用相同:
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'
尝试节点模块请求 (npm install request
)。它使 HTTP 请求更容易处理:
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
});
寻求以下方面的帮助:
为什么下面的工作和return一个200(设置一个事件)
$.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 : {}})
当下面的节点POST没有?
// 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')
});
});
响应是 403,但记录在节点 POST 中实际发送的内容与 AJAX 调用相同:
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'
尝试节点模块请求 (npm install request
)。它使 HTTP 请求更容易处理:
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
});