我正在尝试将 request
与 Bluebird 的 Promises
结合使用:
const request = Promise.promisify(require('request'));
Promise.promisifyAll(request);
不幸的是,我得到的结果并没有反射(reflect)我根据示例所期望的结果:
request('http://google.com').then(function(content) {
// content !== String
// Object.keys(content) => ['0', '1']
};
- 内容不是字符串
- 我必须分别通过
content['0']
访问内容content['1']
,这里是我实际预期的响应,即 HTML 字符串。
这对我来说似乎很可疑,就像我在这里滥用了 Promise API 一样。我做错了什么?
最佳答案
使用 .spread(function(response, content){})
而不是 .then(function(content){})
。
关于javascript - Promised 请求在解析时不会返回正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33015102/