How to Fix Respondinvalid Xml in C#

I was testing the USPS Api, when I got that error.

This is because of the error in my root tag, my request is as follow:

API=Verify&XML=<verifyrequest USERID='207BAZLI7194' PASSWORD='053FG85YP581'><address ID="0">

<address1></Address1><address2>Address2</Address2><city>City</City><state>State</State><zip5>Zip Code</Zip5><zip4></Zip4></Address></VerifyRequest>



As written, I am calling the verify API. What I did wrong was I named the root tag , sure it works on the test server: http://testing.shippingapis.com/ShippingAPITest.dll. But it failed in the production: http://production.shippingapis.com/ShippingAPITest.dll.

Solution:
Just rename the root tag to <addressvalidaterequest>, the xml request becomes:


API=Verify&XML=<addressvalidaterequest USERID='207BAZLI7194' PASSWORD='053FG85YP581'><address ID="0">

<address1></Address1><address2>Address2</Address2><city>City</City><state>State</State><zip5>Zip Code</Zip5><zip4></Zip4></Address></AddressValidateRequest>


Note: It seems USPS is treating address1 as address2 and vice versa. Take note of this :D.

3 Comments

  1. Very unclear written. And you shouldn't display your user name and password!!

    How did you find the correct root tag name?!

    ReplyDelete
  2. Sorry, I updated the script container long time ago and as a result broke my first set of posts just like this one. Anyway I've updated this post.

    ReplyDelete
  3. And don't worry about my username and password, it's either wrong or demo account :-)

    ReplyDelete

Post a Comment

Post a Comment

Previous Post Next Post
NERV Open Source
Building production Spring Boot systems?

Explore NERV — open-source Java libraries for audit trails, persistence, exception handling, and reliable event-driven architecture.