TopKatz
29 May 2007, 7:15 AM
Im trying to make a xml request to the usps to for zipcode validation. Im not very familer with xml, and am having some problems. I think its an encoding issue... but Im not sure.
This is my code:
function testXML(){
var zipDataStore;
var XMLString = '<ZipCodeLookupRequest%20USERID=\"xxxxxxxxxxx\"><Address ID=\"0\"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>';
zipDataStore = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://testing.shippingapis.com/ShippingAPITest.dll'
}),
reader: new Ext.data.XmlReader({
record: "ZipCodeLookupResponse",
totalRecords: "totalCount",
id: "Address ID"
},[
{name: 'Address', mapping: 'Address2'},
{name: 'City', mapping: 'City'},
{name: 'State', mapping: 'State'},
{name: 'Zip5', mapping: 'Zip5'},
{name: 'Zip4', mapping: 'Zip4'}
]),
baseParams: {
API: 'ZipCodeLookup',
XML: XMLString,
totalCount: '1'
}
});
zipDataStore.load();
};
This is what my post looks like:
API ZipCodeLookup
XML <ZipCodeLookupRequest%20USERID="xxxxxxxxx"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>
_dc 1180451819968
callback stcCallback1002
totalCount 1
and this is what the location looks like, which is a 400 response from the server saying it does not understand the request:
http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest%2520USERID%3D%xxxxxxxxxxx%22%3E%3CAddress%20ID%3D%220%22%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E6406%20Ivy%20Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E&totalCount=1&_dc=1180451819968&callback=stcCallback1002
this is the format the server wants:
http://SERVERNAME/ShippingAPITest.dll?API=ZipCodeLookup&XML=<ZipCodeLookupRequest%20USERID="xxxxxxx"><Address ID="0"><Address1></Address1>
<Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>
MD</State></Address></ZipCodeLookupRequest>
What am I missing?
Thanks in advance,
Katz
This is my code:
function testXML(){
var zipDataStore;
var XMLString = '<ZipCodeLookupRequest%20USERID=\"xxxxxxxxxxx\"><Address ID=\"0\"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>';
zipDataStore = new Ext.data.Store({
proxy: new Ext.data.ScriptTagProxy({
url: 'http://testing.shippingapis.com/ShippingAPITest.dll'
}),
reader: new Ext.data.XmlReader({
record: "ZipCodeLookupResponse",
totalRecords: "totalCount",
id: "Address ID"
},[
{name: 'Address', mapping: 'Address2'},
{name: 'City', mapping: 'City'},
{name: 'State', mapping: 'State'},
{name: 'Zip5', mapping: 'Zip5'},
{name: 'Zip4', mapping: 'Zip4'}
]),
baseParams: {
API: 'ZipCodeLookup',
XML: XMLString,
totalCount: '1'
}
});
zipDataStore.load();
};
This is what my post looks like:
API ZipCodeLookup
XML <ZipCodeLookupRequest%20USERID="xxxxxxxxx"><Address ID="0"><Address1></Address1><Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>MD</State></Address></ZipCodeLookupRequest>
_dc 1180451819968
callback stcCallback1002
totalCount 1
and this is what the location looks like, which is a 400 response from the server saying it does not understand the request:
http://testing.shippingapis.com/ShippingAPITest.dll?API=ZipCodeLookup&XML=%3CZipCodeLookupRequest%2520USERID%3D%xxxxxxxxxxx%22%3E%3CAddress%20ID%3D%220%22%3E%3CAddress1%3E%3C%2FAddress1%3E%3CAddress2%3E6406%20Ivy%20Lane%3C%2FAddress2%3E%3CCity%3EGreenbelt%3C%2FCity%3E%3CState%3EMD%3C%2FState%3E%3C%2FAddress%3E%3C%2FZipCodeLookupRequest%3E&totalCount=1&_dc=1180451819968&callback=stcCallback1002
this is the format the server wants:
http://SERVERNAME/ShippingAPITest.dll?API=ZipCodeLookup&XML=<ZipCodeLookupRequest%20USERID="xxxxxxx"><Address ID="0"><Address1></Address1>
<Address2>6406 Ivy Lane</Address2><City>Greenbelt</City><State>
MD</State></Address></ZipCodeLookupRequest>
What am I missing?
Thanks in advance,
Katz