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' }谁能解决;谢谢!!!
通过 curl --referer "http://www.simsimi.com/talk.htm"--cookie "JSESSIONID=A9E30C91FAEFFFD558ED295077F1CBFB"-i --raw http://www.simsimi.com/func/req\?msg\=hello\&lc\=zh
的原始响应 header
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
。
我是一名优秀的程序员,十分优秀!