0

I have an endpoint I'm testing using Node.js node-rest-client

return new Promise(function(resolve, reject) {
    client.post(`${url}/auth/auth`, authArgs, function (authData) {
      if (debug) {
        console.log("Received authData:");
        console.log(authData);
        console.log();

if authData fails the response is in HTML, and when trying to print it I receive the following

Received authData:
<Buffer 49 6e 74 65 67 72 69 74 79 45 72 72 6f 72 20 61 74 20 2f 61 75 74 68 65 6e 74 69 63 61 74 69 6f 6e 2f 61 75 74 68 65 6e 74 69 63 61 74 65 0a 6e 75 6c ... >

How can I have this HTML to be parsed properly so it can show the error message properly instead of a buffer

4

1 回答 1

1

输出错误是Buffer,它是一个二进制流,要将其转换为字符串,您只需执行以下操作:

...
console.log(authData.toString('utf8'));
...
于 2020-01-21T18:59:22.160 回答