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");
}
I want get simsimi by nodejs but always return error { [Error: Parse Error] bytesParsed: 229, code: 'HPE_INVALID_HEADER_TOKEN' } who can resolve; thanks!!!
Raw response headers via 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
You have text/html: utf-8 instead of Content-Type: text/html;charset=UTF-8. Additionally you are not serving html, but json, which means your content type should be application/json.