USPS地址更正
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了USPS地址更正相关的知识,希望对你有一定的参考价值。
requires you to register with USPS.method requires your USPS API key.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net; using System.Web.Configuration; using System.Collections.Specialized; using System.Xml.Linq; using System.IO; public static class AddressProvider { public static Address StandardizeAddress(Address address) { try { //Prepare Request client.Headers.Add("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); string advserver = "http://production.shippingapis.com/ShippingAPI.dll"; string advuserid = // YOU USER ID HERE add.SetAttributeValue("ID", "0"); add.Add(firmname); add.Add(ad1); add.Add(ad2); add.Add(city); add.Add(state); add.Add(zip5); add.Add(zip4); root.SetAttributeValue("USERID", advuserid); root.Add(add); nvc.Add("API", "Verify"); nvc.Add("XML", root.ToString()); byte[] data = client.UploadValues(wa, nvc); string s = reader.ReadToEnd(); //Process Response XElement response = XElement.Parse(s, LoadOptions.None); IEnumerable<XElement> error = response.Descendants("Error"); if (error.Count() <= 0) { XElement xad = response.Element("Address"); if (xad != null) { if (xad.Element("Address1") != null) { addr.Street2 = xad.Element("Address1").Value; } else { addr.Street2 = string.Empty; } if (xad.Element("Address2") != null) { addr.Street1 = xad.Element("Address2").Value; } else { addr.Street1 = string.Empty; } if (xad.Element("City") != null) { addr.City = xad.Element("City").Value; } else { addr.City = string.Empty; } if (xad.Element("State") != null) { addr.State = xad.Element("State").Value; } else { addr.State = string.Empty; } if (xad.Element("Zip5") != null) { addr.Zip = xad.Element("Zip5").Value; } else { addr.Zip = string.Empty; } } } else { return null; } } catch { } return addr; } public class Address { public string Street1 { get; set; } public string Street2 { get; set; } public string City { get; set; } public string State { get; set; } public string Zip { get; set; } } }
以上是关于USPS地址更正的主要内容,如果未能解决你的问题,请参考以下文章
我正在尝试使用 Shippo 获取要在美国境内发送的 USPS 运输标签,但似乎无法显示任何费率
php [USPS送货方式]排除某个国家/地区的USPS费率