返回身体而不是字符串

时间:2018-06-13 17:22:48

标签: javascript node.js async-await requestjs

我有类似的代码:

    // src/getSessionId.js
function callback(error, response) {
  // some code
  return sessionId; // typeof string
}

async function getSessionId(url = DEFAULT_URL) {
  const sessionId = await request.post(url, callback);
  console.log(sessionId); // logs the expected sessionId
  return sessionId;
}

// src/scrape.js
async function scrape() {
  const sessionId = await getSessionId('http://www.someUrl.com/');
  // expected: sessionId === getSessionId is true => the one I logged before
  // actual: sessionId is the response body => <html> ... <body> ... </body> ... </html>
}

我想要预期的sessionId,而不是响应html正文。为什么这不符合我的预期呢?

可以在此处找到代码:https://bitbucket.org/ytNeskews/handelsregister-scraper/src

0 个答案:

没有答案