使用 XML 和 Javascript 的 USPS 地址验证 API

问题描述

我运行了以下代码(输入了我的用户 ID):

const xhttp = new XMLHttpRequest();
const url = 'https://secure.shippingapis.com/ShippingAPI.dll?API=Verify';
xhttp.open('GET',url,true);

xhttp.onreadystatechange = (e) => {
  if (xhttp.readyState == 4 && xhttp.status == 200) {
    console.log('request successful');
    console.log(xhttp.responseXML);
  }
}

let xml = '<AddressValidateRequest USERID="XXXXXXXXXXXX"><Address><Address1>324 Church St</Address1><Address2></Address2><City>Ray</City><State>ND</State><Zip5>58849</Zip5><Zip4></Zip4></Address></AddressValidateRequest>'

xhttp.send(xml);

这是回复

<Error>
  <Number>80040B19</Number>
  <Description>XML Syntax Error: Please check the XML request to see if it can be parsed.</Description>
  <Source>uspsCOM::DoAuth</Source>
</Error>

我不确定我做错了什么。我的 XML 是否正确?我发送正确吗?

资源:USPS Web Tools API Portal

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)