0

我的应用程序使用 express,它托管在 nodejitsu.com 上。仅接收 POST 请求的前 400-1500 个字符。在本地,这不会发生。Chrome 开发工具包显示请求已正常发送。这是我收到请求的方式:

function settings_post(request, response) {
console.log('getting a '+request.method);
if (request.method == 'POST') {
    var body = '';
    request.on('data', function (data) {
        body += data;   //needs to be converted to a string manually, for some reason
        console.log('received POST: '+body);
    });
    request.on('end', function () {
        var obj = qs.parse(body);

        //update settings variable 
        var str = obj.dictionary;
        delete obj.dictionary;
        var array = str.replace(/[\r\n]+$/g, '').split('\r\n');
        console.log('parced array: '+array);    //this doesn't happen

日志显示:

[07/04 15:38:09 GMT] POST / [07/04 15:38:09 GMT] 收到 POST:tabname=TEST_LEVEL1&字典=test%2C+long%0D%0Aand%2C+et%0D%0Aif%2C+si%0D%0Agood%2C+bon%0D%0Ahere%2C+ici%0D%0Ano%2C+non%0D % 0Ayes%2C+oui%0D%0Anice+%28weather%29%2C+beau%0D%0Aexpensive%2C+cher%0D%0Adad%2C+papa%0D%0Ato+read%2C+lire%0D%0Astrong%2C+ good+at+%28subject%29%2C+fort%0D%0AFAL SE%2C+faux%0D%0Ahigh%2C+haut%0D%0Along%2C+long%0D%0Aalone%2C+seul%0D%0Aall%2C +tout%0D%0ATRUE%2C+vrai%0D%0Apretty%2C+joli%0D%0Augly%2C+laid%0D%0Aquick%2C+vite%0D %0Afat%2C+gros%0D%0Atoo%2C+trop %0D%0Aquickly%2C+vite%0D%0Ablue%2C+bleu%0D%0Abrown%2C+brun%0D%0Agrey%2C+gris%0D%0Ablack%2C+noir%0D%0Apink%2C+rose%0D %0Agreen%2C+vert%0D%0Aso%2C+donc%0D%0Abut%2C+mais%0D%0Athen%2C+puis%0D%0AJune%2C+juin%0D%0AMarch%2C+mars%0D% 0Awith%2C+avec%0D%0Ain%2C+dans%0D%0Afor%2C+in+order%2C+pour%0D%0Aat+%28someone%E2%80%99s+house%29%2C+chez%0D%0Awithout%2C+sans%0D%0Aexcept%2C+sauf%0D%0Aunder%2C+sous%0D%0Atowards%2C+vers% 0D%0Ahalf%2C+demi%0D%0AWhat%3F%2C+que%3F%0D%0AWho%3F%2C+qui%3F%0D%0Ayesterday%2C+hier%0D%0Ato+say%2C+dire% 0D%0Ato+see%2C+voir%0D%0Ato+laugh%2C+rire%0D%0Ato+hire%2C+to+rent%2C+louer%0D%0Afree%2C+available%2C+vacant%2C +libre%0D%0Ato+put+someone+up%2C+to+accommodate%2C+loger%0D%0Ato+go%2C+aller%0D%0Acold%2C+froid%0D%0Ato+pay%2C+payer %0D%0新鲜%2C+frais%0D%0A the+water%2C+l%27eau%0D%0Ato+fit%2C+to+suit%2C+过敏%0D%0Abig%2C+grand%0D%0Awide% 2C+large%0D%0Ato+like%2C+aimer%0D%0Amum%2C+maman%0D%0Anice%2C+likeable%2C+sympa %0D%0Aold+%28masculine%29%2C+vieux%0D%0Ayoung+ pe [07/04 15:38:09 GMT] 收到 POST格林威治标准时间 09] 得到一个 POST格林威治标准时间 09] 得到一个 POST格林威治标准时间 09] 得到一个 POST格林威治标准时间 09] 得到一个 POST

限制似乎是任意的,这不会在本地发生。有任何想法吗?

4

1 回答 1

0

问题是我在收到 POST 请求后立即重定向,这就是为什么我只看到 POST 的第一块。将重定向移动到“结束”事件解决了这个问题。

由于我的代码在只有一个 POST 块的情况下有效,因此它可以在短 POST 以及本地上工作。这不是快递或主机的问题,只是我的错误代码。

于 2013-07-09T08:05:05.393 回答