尝试使用 USPS Tracking API 检索 USPS 订单的状态时引发错误。
但是,在运行我根据 USPS 手册构建的代码时,出现以下错误:“ 80040B19XML Syntax Error: Please check the XML request to see if it can be parsed.USPSCOM::DoAuth ”
手册链接:https ://www.usps.com/business/web-tools-apis/track-and-confirm-v1-3a.htm
这是我的代码:
$trackingNumber = 123456;
$url = "http://production.shippingapis.com/shippingAPI.dll";
$service = "TrackV2";
$xml = rawurlencode("
<TrackRequest USERID='MYID'>
<TrackID ID=".$trackingNumber."></TrackID>
</TrackRequest>");
$request = $url . "?API=" . $service . "&XML=" . $xml;
// send the POST values to USPS
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$request);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// parameters to post
$result = curl_exec($ch);
//var_dump($result);
curl_close($ch);
$response = new SimpleXMLElement($result);
//print_r($result);
$deliveryStatus = $response->TrackResponse->TrackInfo->Status;
echo $deliveryStatus;
我究竟做错了什么?