![]() ![]() (This library will work in ASP.NET Web applications also.) The USPS Web tools are fairly easy to integrate, but I wanted to create a reusable component that I could use in future projects. ![]() I was in need of a library that would integrate the USPS Web Tools into my Windows form application. I will post them here on The Code Project when I am finished, but you can check this Web site until then for updates and to contact me directly. The DHL version should be the next one I release. To do that, we need to use the array $contents that the xml has been put in.UPDATE: I am working on a FedEx, UPS and DHL version of this tool. What next? Well, now we need to parse the xml into something usable. Which is exactly what it should return on a successful test. It looks like this because it is not parsing the xml or using any html formatting. If you run this code, it will display like so, at least echoed to an HTML page in Opera 11: Usually if I’m coding something like this, I like to simply echo it to the page to see what it’s returning before I move forward. The final line, echo $xmldata, is used for testing. However, I’m sure it seemed like a logical decision at the time, and I simply haven’t gone back through all this code to clean it up. Looking at the code, I likely don’t need the $xml = $newurl line, as I’m simply creating a new variable out of one that already exists. Xml_parse_into_struct($parser,$xmldata,$values) To do that, once I’ve gotten the response, I used this: I needed to parse out the xml into something that could be put on an HTML page. I used a little variation on this, as simply echoing $contents doesn’t do me any good. The test server will return the response in $newurl, and you use the $contents=file_get_contents($newurl) to retrieve it. Once you have gotten those to work, there are some more hoops to jump through (more on that later.)įor this, simply plug your User ID in where the code reads USERID=”xxxxxxxx”. When you have gotten your User ID, you have to run two scripted tests on their testing server. Incidentally, if you haven’t looked at it yet, this is the first ‘scripted’ test USPS will have you run. It is apparently unknown who wrote it originally, but thank god he did, and thank god Denver Dave reposted it. I found that here in the post by Denver Dave. This time, I found something that looked likely – it was a short little bit of code, and I could see exactly how I could use it on the existing page I was using to give me the results I wanted. Sunday night, I couldn’t let it go, so I searched again. But I couldn’t, so I kicked it old school with some GTA San Andreas instead. I will again point out that I have a shaky handle at best on PHP, so it may entirely be that any of them would have worked, had I been smart enough to figure it out. There was a wealth of code people had used, but I couldn’t figure out a way to modify it for my purposes. I spent an entire Saturday, 10 or so hours, searching the web looking for code that would work for me. That’s all on you.įor me, I needed PHP, as that’s only one I’ve really worked with to have any sort of idea of what I’m doing. They will tell you what you need to send, but now how to send it. Essentially, any language capable of sending and receiving xml to and from remote servers will work – VB, Perl, PHP, etc. ![]() They start with the warning that you need to have a handle on web development with the usual sorts of languages, html, xml, etc. They also provide an implementation guide that is a little less than perfect. Shortly, you will receive an email with a user ID and password. Go to the Web Tools sign-up page and give them the expected sort of information. To use the USPS Web Tools API, you have to sign up and get a user ID and password. While some references may be outdated, the code still works, as I’m still using it today.) (Note: this was originally written in 2010, to the best of my memory. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |