【发布时间】:2014-03-07 01:54:01
【问题描述】:
在我的浏览器中加载此链接时,该链接由 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>
任何帮助将不胜感激
【问题讨论】:
-
请注意,SO 是一个国际论坛,如果你不说你来自哪个国家,我们不知道你所说的“国内”是什么意思。 (哦,我猜“USPS”可能会提供线索——比如美国邮政服务或美国包裹服务?)
-
您的评论让我很好奇我所指的国家是否有标识符,即美国。最明确的方法是在我链接的域上进行 WHOIS shippingapis.com,这将为您提供所有者的姓名、地址、电话号码和电子邮件。
标签: javascript xml api google-apps-script usps