[ACCEPTED]-How to validate the given address using USPS?-c#
The United States Postal Service (USPS) does 8 offer this service via their Address Information 7 APIs:
Here's a Code Project article/library 6 how you could use this services in .NET:
///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 servers Address validatedAddress = m.ValidateAddress(a);
NOTE: For some reason, you need to put 4 the actual Address as Address2. If you attempt 3 to put Address1 as "6406 Ivy Lane" it 2 will fail. Address1 is apparently for apartment 1 or suite number. Courtesy Simon Weaver's comment below.
If I may chime in here -- I used to work 16 in the address validation industry for SmartyStreets, which 15 is a CASS-Certified vendor of these services.
Note 14 first that, while the USPS is the authority 13 on address data, their forte is NOT maintaining an API and providing support. Also, be sure to note 12 the agreement which you signed:
- User agrees to use the USPS Web site, APIs and USPS data to facilitate USPS shipping transactions only.
So unless 11 you're mailing or shipping with the USPS 10 by the use of their API, it's not agreeable 9 to use the API at all. This among the other 8 problems you're having is grounds to look 7 for a better solution -- if I was you.
Anyway, there 6 are actually quite a few out there. I'll 5 let you do your own research, but of course 4 I would suggest one that I've worked on 3 called LiveAddress. It's free, and returns 2 more data and is more reliable than the 1 USPS' API.
Update: Here's some C# code examples on GitHub that will probably be useful.
More Related questions