Yamila
Yamila

Reputation: 443

Response encoding node-soap

I'm trying to fetch utf-8 characters (accents) using node-soap but i'm getting strange chars (printed in console as '?'). I'm able to see accents in Soap UI.

soap.createClient('https://example.com/data.php?wsdl',options, (err, client) => {
    if (err) return next(err);

    client.getPerson({args}, (err, result) => {})
    let name = result.data.name.$value;
    //BUG name contains invalid chars instead of accents
});

Upvotes: 1

Views: 820

Answers (1)

fxdeltombe
fxdeltombe

Reputation: 61

� is the replacement character, set by js to figure any byte than can not be displayed : either a special ascii character (from \x00 to \x1F, and \x7F), or a non-ASCII byte (unless it is a part of an utf-8 character).

So, it seems that your SOAP response is not utf8-encoded. Soap UI must be implemented so as to find out the original encoding and display it properly. But your js engine does not, and replaces invalid utf8 characters in strings with �.

In node-soap, you can use in Client.service.port.method (and also in Client.method whereas it is not documented) an option from request module to get these characters encoded : for example

client.getPerson(
    {args},
    (err, result) => {},
    { encoding: 'latin1' } // you can add any option from request module ;
                           // `encoding` will point out the response encoding
)

Upvotes: 1

Related Questions