示例#1
0
        public TrackingInfo GetTrackingInfo(string USPSAPIUserName, string USPSAPIPassword, string TrackingNumber)
        {
            try
            {
                string trackurl = "?API=TrackV2&XML=<TrackRequest USERID='" + USPSAPIUserName + "' PASSWORD='******'><TrackID ID='" + TrackingNumber + "'></TrackID></TrackRequest>";
                string url      = GetURL() + trackurl;
                url = String.Format(url, _userid, TrackingNumber);
                string xml = web.DownloadString(url);
                if (xml.Contains("<Error>"))
                {
                    try
                    {
                        int    idx1    = xml.IndexOf("<Description>") + 13;
                        int    idx2    = xml.IndexOf("</Description>");
                        int    l       = xml.Length;
                        string errDesc = xml.Substring(idx1, idx2 - idx1);
                        //throw new USPSManagerException(errDesc);
                    }
                    catch (Exception ex)
                    {
                        return(TrackingInfo.FromXml(ex.ToString()));
                    }
                }

                return(TrackingInfo.FromXml(xml));
            }
            catch (WebException ex)
            {
                throw new USPSManagerException(ex);
            }
        }
示例#2
0
        public static TrackingInfo FromXml(string xml)
        {
            int          idx1 = 0;
            int          idx2 = 0;
            TrackingInfo t    = new TrackingInfo();

            if (xml.Contains("<TrackSummary>"))
            {
                idx1       = xml.IndexOf("<TrackSummary>") + 14;
                idx2       = xml.IndexOf("</TrackSummary>");
                t._Summary = xml.Substring(idx1, idx2 - idx1);
            }
            int lastidx = 0;

            while (xml.IndexOf("<TrackDetail>", lastidx) > -1)
            {
                idx1 = xml.IndexOf("<TrackDetail>", lastidx) + 13;
                idx2 = xml.IndexOf("</TrackDetail>", lastidx + 13);
                t.Details.Add(xml.Substring(idx1, idx2 - idx1));
                lastidx = idx2;
            }
            return(t);
        }