响应编码节点肥皂

时间:2018-10-04 01:09:10

标签: node-soap

我正在尝试使用节点肥皂来获取utf-8字符(重音符),但是却遇到了奇怪的字符(在控制台中以“?”打印)。我可以在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
});

1 个答案:

答案 0 :(得分:1)

。是replacement character,由js设置,以计算无法显示的任何字节:特殊的ascii字符(从\ x00到\ x1F和\ x7F)或非ASCII字节(除非它是utf-8字符的一部分)。

因此,您的SOAP响应似乎未经过utf8编码。 必须实现Soap UI,以便找出原始编码并正确显示。 但是您的js引擎不会,而是用``。''替换字符串中的无效utf8字符。

在节点肥皂中,您可以在Client。 service.port.method 中使用(也可以在Client。 method 中使用,但未记录)请求中的选项模块来对这些字符进行编码:例如

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