2017-08-10 70 views
2

我正在嘗試https://github.com/IonicaBizau/tinyreq。看看這些文檔,我使用回調來運行示例沒有任何問題。使用tinyreq與承諾

const tinyreq = require("tinyreq"); 

// Make a request to example.com 
tinyreq("http://example.com/", (err, body) => { 
    console.log(err || body); 
}); 

但是使用承諾語法沒有給出輸出作爲列出的例子。

// Make a request with custom headers 
// Using a promise 
tinyreq({ 
    url: "http://example.com/" 
    , headers: { 
     "user-agent": "Crawler/1.0" 
    } 
}).then(body => { 
    console.log(body); 
}).catch(err => { 
    console.log(err); 
}); 

我正在使用節點版本8.3.0。我究竟做錯了什麼?

回答

1

這真是個錯誤!謝謝!


解決here。除非提供回調,否則Tinyreq不會存儲響應主體。現在,當致電then Tinyreq知道它必須存儲響應主體。

這是修復:

str.then = fn => { 
callback = callback || noop 
    return opt_callback._.then(fn) 
}