2012-06-08 106 views
0

當確認地址,我得到這個錯誤:USPS地址驗證失敗

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

或者我得到另一個錯誤說的地址無法找到。有沒有更好的方法來驗證這個地址?

這裏是我的網址:

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

請不要修改這個問題,打破XML了多行,因爲這這不是OP發送的內容。該OP將URL作爲單行發送。如果您需要查看[XML自身是否「有效」,請參閱下面的轉儲](http://pastie.org/4052770)。 – user7116

回答

3

據我所看到的錯誤描述,該問題可能是,你需要把它添加到URL 前從XML中除去\r\n。不要忘記也要對它進行網址編碼。

+0

我原本編輯的URL準確地反映了OP發送到服務器的內容,然而,ErikPhilips添加了新行......但是+1對「Url編碼」進行了編碼。 – user7116

+0

@sixlettervariables:感謝您的信息。 –

+0

如果我說123 Main St#41,我需要刪除#號,所以出現了編碼問題。此外,街道地址應在地址2上,而適配號在地址1上 –

0

你實際上需要HtmlEncode它,然後UrlEncode它。 這是becasue你實際發送XML(這需要&amp;代替&),但它的一個URL因此它需要編碼,使每個&%26

下面是一個完整的工作URL - 你只需把你的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> 

你會看到它包含了這個時髦尋找字符串:

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

這我做這個:

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

[此特定錯誤我回來的時候我沒」牛逼編碼正確是Error Loading XML: Whitespace is not allowed at this location]