SitePoint Sponsor

User Tag List

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

    PHP XML & get - Can I do this 0r do I need Snoopy

    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); (I did put the correct user and password and changed all double quotes to single quotes) 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

  2. #2
    You talkin to me? Anarchos's Avatar
    Join Date
    Oct 2000
    Location
    Austin, TX
    Posts
    1,438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bernn I spent the better half of yesterday trying to figure this one out, but no such luck. I mean right on usps site is says those are valid get requests. But what I think is missing is a way to connect to the server and pass that xml request. I tried looking through the XML docs for PHP, but couldn't figure it out. I know a little further down the page in the usps docs it gives examples for ASP, Perl and Java, but none for PHP. I do want to figure out how it works so I will be trying some more, and will let you know if I figure it out.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  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)
    Bernn,

    I got it all figured out for you. First get snoopy, it just makes life easier. http://sourceforge.net/projects/snoopy/

    Here is the script I used and it worked perfect.
    PHP Code:
    <?
        
    include "Snoopy.class.inc";
        
    $snoopy = new Snoopy;
        
    $msg '<RateRequest USERID="159JOHNC2479" PASSWORD="234VE51TI212">
                    <Package ID="0">
                        <Service>EXPRESS</Service>
                        <ZipOrigination>20770</ZipOrigination>
                        <ZipDestination>20852</ZipDestination>
                        <Pounds>10</Pounds>
                        <Ounces>0</Ounces>
                        <Container>None</Container>
                        <Size>REGULAR</Size>
                        <Machinable></Machinable>
                    </Package>
                </RateRequest>'
    ;
        
    $submit_url "http://testing.shippingapis.com/ShippingAPITest.dll";
        
    $submit_vars["API"] = "Rate";
        
    $submit_vars["XML"] = $msg;
        
    $snoopy->submit($submit_url,$submit_vars);
        print 
    "<PRE>".htmlspecialchars($snoopy->results)."</PRE>\n";
    ?>
    NOw I will leave it up to you to format the return xml message, but this is how to send the request.
    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)

    Thank You

    Your code works splendidly ... thanks for the help

    Bernn

  6. #6
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No problem and see you at the Garlic Festival
    Please don't PM me with questions.
    Use the forums, that is what they are here for.


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
  •