CNode

node.js 发送HTTP消息时报错,非常诡异,球破!

Iimaxlove发布于14 年前最后回复14 年前10 回复8744 浏览0 收藏

正常往sina发送HTTP请求,但是会不时报如下错误, POST: api.weibo.com:443 /2/statuses/repost.json access_token=2.00rhElVDGI631Ee549f6f303v86EQB&id=3534310755900989&status=imax_check

Error: socket hang up at SecurePair.error (tls.js:948:15) at EncryptedStream.CryptoStream._done (tls.js:432:17) at EncryptedStream.CryptoStream._pull (tls.js:577:12) at SecurePair.cycle (tls.js:866:20) at EncryptedStream.CryptoStream.end (tls.js:405:13) at Socket.onend (stream.js:66:10) at Socket.EventEmitter.emit (events.js:123:20) at TCP.onread (net.js:417:51) 有人知道啥原因不?

查看回复

回复 (10)

I
imaxlove#1·14 年前

@Jackson

J
jiyinyiyong#2·14 年前

不贴代码的话我想你只应该到新浪 API 的论坛问..

I
imaxlove#3·14 年前
引用 jiyinyiyong不贴代码的话我想你只应该到新浪 API 的论坛问..

data = ‘access_token=2.00rhElVDGI631Ee549f6f303v86EQB&id=3534310755900989&status=imax_check’ var options = { hostname: 'api.weibo.com', port: 443, path: '/2/statuses/repost.json', method: 'POST' };

var req = http.request(options, function(res) { console.log('STATUS: ' + res.statusCode); }); });

req.on('error', function(e) { console.log('problem with request: ' + e.message); });

// write data to request body req.write('data\n'); req.end();

J
jiyinyiyong#5·14 年前

除了一层括号有错外(我手动去掉了).. 我运行是成功的, 这不是你出错的代码对吧

var http = require('http');

var options = {
  hostname: 'api.weibo.com',
  port: 443,
  path: '/2/statuses/repost.json',
  method: 'POST'
};

var req = http.request(options, function(res) {
  console.log('STATUS: ' + res.statusCode);
});

req.on('error', function(e) {
  console.log('problem with request: ' + e.message);
});

// write data to request body
req.write('data\n');
req.end();
I
imaxlove#6·14 年前
引用 jiyinyiyong除了一层括号有错外(我手动去掉了).. 我运行是成功的, 这不是你出错的代码对吧

出错的代码和这个一模一样,我这边只有一个环境会不时的抱着个错,我看过源码包,貌似是ssl什么地方出错了,手动运行怎么都不能重现,但是就会时不时的发生这种错。。。十分无奈。

L
leapon#7·14 年前

或许是新浪服务器端的不作为吧。

我的运行结果: $ node test.js STATUS: 411

J
JacksonTian#8·14 年前

443不该是用https模块来进行访问吗?

L
leapon#9·14 年前

我的关于443的回复怎莫不见了?

Jackson 对 443 的建议是对的。可是我改用 https 得到相同的结果。

$ node test.js 
STATUS: 411
D
DoubleSpout#10·14 年前
引用 leapon我的关于443的回复怎莫不见了? Jackson 对 443 的建议是对的。可是我改用 https 得到相同的结果。 $ node test.js STATUS: 411

411错误码是你post时http头content-length不对,你代码里没有发这个header,基本上4xx错误码都是客户端请求错误引起的

参与回复
登录后即可参与回复。登录