USPS Address Validation Fail

拈花ヽ惹草 提交于 2019-12-11 18:23:29

问题


When validating an address, I get this error:

ex = {"Error Loading XML:  The following tags were not closed: AddressValidateRequest, Address, Address1.\r\n"}

or I get another error saying the address cannot be found. Is there a better way to validate this address?

Here is my URL:

http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="402JMAWE3481"><Address ID="1"><Address1>123 Main St</Address1><Address2></Address2><City>Watertown</City><State>MA</State><Zip5>02472</Zip5><Zip4></Zip4></Address></AddressValidateRequest>

回答1:


According what I see on the error description, the problem could be that you need to remove \r\n from the xml before adding it to the url. Don't forget also to url encode it.




回答2:


You actually need to HtmlEncode it and then UrlEncode it. This is becasue you're actually sending XML (which requires &amp; instead of &) but its a URL so it needs encoding to make each & into %26

Here's a complete working URL - you just need to put in your USERID.

http://production.shippingapis.com/ShippingAPI.dll?API=Verify&XML=<AddressValidateRequest USERID="123USERID567"><Address ID="1"><Address1></Address1><Address2>10051+Orr+%26amp%3b+Day+Rd</Address2><City>santa+fe+springs</City><State>ca</State><Zip5>90670</Zip5><Zip4></Zip4></Address></AddressValidateRequest>

You'll see it contains this funky looking string:

 10051+Orr+%26amp%3b+Day+Rd

Which I got by doing this :

 HttpUtility.UrlEncode(HttpUtility.HtmlEncode("10061 Orr & Day Rd"))

[This specific error I got back when I didn't encode properly was Error Loading XML: Whitespace is not allowed at this location]



来源:https://stackoverflow.com/questions/10955988/usps-address-validation-fail

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!