在我的浏览器中加载此链接后,该链接由 USPS 提供的用户 ID 和有关包裹的详细信息组成
Link: http://production.shippingapis.com/ShippingAPITest.dll?API=RateV4&XML=<RateV4Request USERID="[userid]"><Revision/><Package ID="1ST"><Service>PRIORITY</Service><ZipOrigination>02211</ZipOrigination><ZipDestination>90210</ZipDestination><Pounds>5</Pounds><Ounces>2</Ounces><Container>RECTANGULAR</Container><Size>LARGE</Size><Width>15</Width><Length>30</Length><Height>15</Height><Girth>55</Girth></Package></RateV4Request>
我返回了正确的结果(下)
<RateV4Response>
<Package ID="1ST">
<ZipOrigination>02211</ZipOrigination>
<ZipDestination>90210</ZipDestination>
<Pounds>5</Pounds>
<Ounces>2</Ounces>
<Container>RECTANGULAR</Container>
<Size>LARGE</Size>
<Width>15</Width>
<Length>30</Length>
<Height>15</Height>
<Zone>8</Zone>
<Postage CLASSID="1">
<MailService>Priority Mail 2-Day<sup>™</sup></MailService>
<Rate>86.65</Rate>
</Postage>
</Package>
</RateV4Response>
但是,当尝试使用以下代码块从 Google Apps 脚本编辑器中的函数加载 API 时:
function xmlLoader(){
var pounds = 5;
var ounces = 2;
var userid = "[userid]";
var url = "http://production.shippingapis.com/ShippingAPI.dll";
var options =
{
"API" : "RateV4",
"XML" : "<RateV4Request USERID=\"" + userid + "\"> \
<Revision/> \
<Package ID=\"1ST\"> \
<Service>PRIORITY</Service> \
<ZipOrigination>02211</ZipOrigination> \
<ZipDestination>90210</ZipDestination> \
<Pounds>" + pounds + "</Pounds> \
<Ounces>" + ounces + "</Ounces> \
<Container>RECTANGULAR</Container> \
<Size>LARGE</Size> \
<Width>15</Width> \
<Length>30</Length> \
<Height>15</Height> \
<Girth>55</Girth> \
</Package> \
</RateV4Request>"
};
var response = UrlFetchApp.fetch(url, options);
Logger.log(response.getContentText());
};
这是我返回的错误,
<?xml version="1.0" encoding="UTF-8"?>
<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>
任何帮助将不胜感激