【发布时间】:2017-01-20 02:37:23
【问题描述】:
我正在使用 cURL 向 usps 运费计算器提交 POST 信息。
$info = "<?xml version='1.0' encoding='UTF-8'?>
<RateV4Request USERID='xxxx'>
<Package ID='$aucid'>
<Service>Priority</Service>
<ZipOrigination>xxxx</ZipOrigination>
<ZipDestination>$zip</ZipDestination>
<Size>$size</Size>
<Pounds>$pounds</Pounds>
<Ounces>$ounces</Ounces>
<Container>RECTANGULAR</Container>
<Width>$width</Width>
<Length>$length</Length>
<Height>$height</Height>
<SpecialServices><SpecialService>108</SpecialService></SpecialServices>
</Package>
</RateV4Request>";
$array = array("API" => "RateV4", "XML" => $info);
$link = "http://production.shippingapis.com/ShippingAPI.dll";
curl_setopt($ch, CURLOPT_URL,$link);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$array);
$answer=curl_exec($ch);
echo $answer;
curl_close($ch);
当我注册 USPS 网络工具时,发送了一封带有 USERID 的电子邮件(由于其敏感性质,我已将其替换为 xs)。
在同一封电子邮件中,指定允许费率计算。 这是返回的错误:
80040B19XML 语法错误:
请检查 XML 请求是否可以解析。USPSCOM::DoAuth
我继续将回显的 XML 插入 xmlvalidation.com 并没有发现任何错误。我也试过在顶部没有<?xml version="1.0" encoding="UTF-8"> 行。
【问题讨论】:
-
你有 curl_init 吗?
-
您确定这些值(例如:
$pounds)正在更新为真实值(数字),而不仅仅是字符串“$pounds”吗? -
@user2182349 是的,在上面。
-
@jonmrich 是的,这些值正在传入,我在将其内容类型转换为文本以便显示标签后的某个时间点回显了它。那是我复制到验证网站的代码。
-
你的
$package_id全是数字吗?