C# · 12月 27, 2021

c# – 如何使用USPS验证给定的地址?

我想验证给予的地址(地址,城市,州,邮政编码)给USPS并返回结果,如果提供的地址是一个有效的地址.并且如果不是有效地址返回无效地址.

那么我如何在C#.Net中做到这一点.

解决方法 从 here ///Create a new instance of the USPS Manager class///The constructor takes 2 arguments,the first is///your USPS Web Tools User ID and the second is ///true if you want to use the USPS Test Servers.USPSManager m = new USPSManager(“YOUR_USER_ID”,true);Address a = new Address();a.Address2 = “6406 Ivy Lane”;a.City = “Greenbelt”;a.State = “MD”;///By calling ValidateAddress on the USPSManager object,///you get an Address object that has been validated by the///USPS serversAddress validatedAddress = m.ValidateAddress(a);