gpt4 book ai didi

node.js - 为什么通过nodejs获取simsimi错误

转载 作者:太空宇宙 更新时间:2023-11-04 02:41:49 25 4
gpt4 key购买 nike

    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

关于node.js - 为什么通过nodejs获取simsimi错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14199933/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com