SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Gilroy, CA
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP & XML - how to use USPS and UPS Servers

    I've been searching through the aritcles for an example of PHP using XML to query and retrieve responses from a remote server. Specifically, I'd like to query the USPS and UPS rate quoting services for an e-commerce site.

    All the examples seem to be parsing XML files, and not responses from remote servers. USPS and UPS don't provide coding examples for PHP. Can anyone get me started or point me in the right direction? I don't understand how to make the HTTP request (although it seems like a simple Http post) and then retrieve the response for parsing.

    Thanks,
    Bernn

  2. #2
    SitePoint Zealot New Oddity's Avatar
    Join Date
    Jun 2001
    Location
    Georgia
    Posts
    102
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $fcontents file("http://www.doamian.com.path/to/certain.page"); 
    This will put the file's contents into an array. Each part of the array is a line from the file... You just parse it out from there...
    --Odd
    "We all live in a yellow subroutine."
    "Some call it insanity; I call it inspiration!"

  3. #3
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Gilroy, CA
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need a little bit more

    Thank you, that was what I was looking for, but I need a little bit more. How do I submit information if it is required to come as a post method rather than get?

    Thanks again

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You will need to send the correct headers, if you need to do GET and POST methods through http, I would suggest looking at snoopy, a php class for simulating GET and POST methods on HTTP requests.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    SitePoint Enthusiast
    Join Date
    May 2001
    Location
    Gilroy, CA
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Do I need snoopy to use Get?

    The USPS offers this request as a valid request:

    Http://SERVERNAME/ShippingAPITest.dll?API=Rate&XML=<RateRequest>
    USERID="xxxxxxxx" PASSWORD="xxxxxxxx"><Package ID="0"><Service>
    EXPRESS</Service><ZipOrigination>20770</ZipOrigination><ZipDestination>20852<
    /ZipDestination><Pounds>10</Pounds><Ounces>0</Ounces><Container>None</Contain
    er><Size>REGULAR</Size><Machinable></Machinable></Package></RateRequest>



    if I put this into file($abovestring); it sends a request but ignores everything within<> so I get the following error:

    Warning: file("Http://testing.shippingapis.com/ShippingAPITest.dll?API=Rate&XML=EXPRESS2077020852100NoneREGULAR") - No such file or directory in /home/sites/home/web/testxml.php on line 5

    Is this a problem with the <> in the string, or is this not a valid way to send information with GET?

    Thanks,
    bernn


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •