1
    var request = require('request');
    var cookie = null;

    var say = function(msg, cb) {
       request({
          'url': 'http://www.simsimi.com/func/req?msg=' + encodeURIComponent(msg) + '&lc=zh',
          'method': 'get',
          'headers': {
          'Cookie': cookie,
              'Referer': 'http://www.simsimi.com/talk.htm'
          }
       }, function(error, response, body) {
          console.log(error);
          console.log(response);
          console.log(body);
       });
    }

request({
   'url': 'http://www.simsimi.com/talk.htm',
   'method': 'get'
}, function(error, response, body) {
    cookie = response.headers['set-cookie'];
    cookie = (cookie + "").split(";").shift();
    console.log(cookie);
    say("hello");
}

我想通过 nodejs 获取 simsimi 但总是返回错误 { [Error: Parse Error] bytesParsed: 229, code: 'HPE_INVALID_HEADER_TOKEN' } 谁能解决;谢谢!!!

4

1 回答 1

0

原始响应标头通过curl --referer "http://www.simsimi.com/talk.htm" --cookie "JSESSIONID=A9E30C91FAEFFDD558ED295077F1CBFB" -i --raw http://www.simsimi.com/func/req\?msg\=hello\&lc\=zh

HTTP/1.1 200 OK
Cache-Control: no-cache
Content-Language: en
Content-Type: text/html;charset=UTF-8
Date: Mon, 07 Jan 2013 22:52:07 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Pragma: no-cache
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=0A6EF5185D0AFF3BAA3E25425B047687; Path=/; HttpOnly
text/html: utf-8
Content-Length: 57
Connection: keep-alive

你有text/html: utf-8而不是Content-Type: text/html;charset=UTF-8. 此外,您提供的不是 html,而是 json,这意味着您的内容类型应该是application/json.

于 2013-01-07T22:54:23.413 回答