【问题标题】:What is the proper way to close a client in restify?在restify中关闭客户的正确方法是什么?
【发布时间】:2013-04-25 01:10:02
【问题描述】:

我有一个接收 POST 的 restify 服务器,然后它会回复一个 POST 调用。我正在使用字符串客户端模块。下面是代码:

var restify = require('restify');

var client = restify.createStringClient({
   url: 'https://xyz.com'
 });

var postdata = {
  ...
 };

 client.basicAuth('username','pass');

 client.post('/somepath',postdata,
            function(err, req, res, data) {
                if(err) ... else { ... };
                //should the close method be called here??
      });

POST 是成功的,但是当我在 REPL 中对其进行测试时,该过程似乎永远不会终止。似乎表明连接仍处于打开状态。是否应该在回调中关闭连接?

任何指针将不胜感激。谢谢。

【问题讨论】:

    标签: node.js client restify


    【解决方案1】:

    Restify StringClient 继承自 HttpClient... 有一个 close() 方法...你试过了吗?

    【讨论】:

    • 谢谢,让-米歇尔。我试过了,它奏效了。我在 post 方法的回调中插入了 close() 。我很好奇它是否是正确的地方。如果我再次拨打电话会怎样?
    • 我认为这行不通...在我看来,只要您需要,您就应该让客户端保持打开状态(在大多数情况下,这应该不是问题...)
    猜你喜欢
    • 2012-04-15
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-05
    • 2016-02-27
    相关资源
    最近更新 更多