嘗試使用USPS跟蹤API檢索USPS訂單的狀態時會引發錯誤。使用PHP獲取USPS訂單跟蹤狀態
但是,運行我建基於美國郵政手動代碼的時候,我收到以下錯誤: 「80040B19XML語法錯誤:請檢查XML請求,看它是否能夠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;
我在做什麼錯?
您是否嘗試回顯$ xml的值以查看它是否是您認爲的值? – Orangepill