首页 > 解决方案 > 错误:节点中的肥皂客户端的 XML 格式无效(联邦快递)

问题描述

我在节点中使用肥皂向 Fedex Web 服务发出请求以上传文件。要上传的文档可以是转换为 base64 的有效文件类型(比方说,多页的 pdf)。如果此 PDF 必须只有一个页面,则流程完全可以正常工作。但是,如果 PDF 是多页的,我会从 Fedex 收到以下错误:

"Invalid XML","detail":"Error: Unexpected close tag\nLine: 0\nColumn: 127\nChar: >".

为了调试这个,我提取了发送到联邦快递的 xml 请求:

<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:ns="http://fedex.com/ws/uploaddocument/v11"><soap:Body><ns:UploadDocumentsRequest xmlns:ns="http://fedex.com/ws/uploaddocument/v11" xmlns="http://fedex.com/ws/uploaddocument/v11"><ns:WebAuthenticationDetail><ns:UserCredential><ns:Key>*******</ns:Key><ns:Password>******</ns:Password></ns:UserCredential></ns:WebAuthenticationDetail><ns:ClientDetail><ns:AccountNumber>*****</ns:AccountNumber><ns:MeterNumber>*****</ns:MeterNumber></ns:ClientDetail><ns:Version><ns:ServiceId>cdus</ns:ServiceId><ns:Major>11</ns:Major><ns:Intermediate>0</ns:Intermediate><ns:Minor>0</ns:Minor></ns:Version><ns:OriginCountryCode>IN</ns:OriginCountryCode><ns:DestinationCountryCode>CN</ns:DestinationCountryCode><ns:Usage>ELECTRONIC_TRADE_DOCUMENTS</ns:Usage><ns:Documents><ns:CustomerReference></ns:CustomerReference><ns:DocumentType>PRO_FORMA_INVOICE</ns:DocumentType><ns:FileName>1810e200-4467-11e8-b6a8-07a18eeb7b1a.pdf-test.pdf</ns:FileName><ns:DocumentContent>Base64String</ns:DocumentContent></ns:Documents></ns:UploadDocumentsRequest></soap:Body></soap:Envelope>  

请求中的变量“Base64String”可以假定为正在发送的文件。关于这个错误是什么以及这有什么意义的任何帮助?让我知道是否可能需要任何其他信息

标签: node.jsxmlsoapsoap-clientfedex

解决方案


如果您使用 xml2js 来转换您的请求,这很可能是这种情况,请确保您升级到版本 0.4.2。首先删除它,然后安装该版本:

npm uninstall --save xml2js  
npm install --save xml2js@0.4.2

此问题已在此版本中处理


推荐阅读