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 Post for UPS

    You guys did a wonderful job helping me get xml responses from the usps, but ups seems a little different. Their site requires a post method, not a get, and the code we used for usps where the xml was supplied as a get variable doesn't look like it's going to work. Here's there sample code using Java:

    ry {
    // Create new URL and connect
    URL url = new URL(protocol + "://" + hostname + prefix + service);
    HttpURLConnection connection = (HttpURLConnection) url.openConnection();

    // Setup HTTP POST parameters
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setUseCaches(false);
    // Get POST data from input file (XML Document)
    String queryString = readInputFile(infile);

    // POST data
    OutputStream out = connection.getOutputStream();
    try {
    out.write(queryString.getBytes());
    out.close();

    // Get Response HTTP Header parameters
    if (connection.getResponseCode() == 302) {
    String data = "";
    try {
    data = readURLConnection(connection);
    } catch (Exception e) {
    // exception raised because HTTP status of 400/500 occur, do nothing
    }
    try {
    writeOutputFile(data, outfile);
    } catch (Exception e) {
    System.out.println("Error writing output file " + outfile);
    }
    } catch (Exception e) {
    System.out.println("Error sending data to server");
    }
    } catch (Exception e) {
    System.out.println(e);
    }

    Thanks again in advance for the help.
    Bernn

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bernn

    Check out this script.
    http://px.sklar.com/code-pretty.html?code_id=244

    Its a php class for getting UPS shipping costs and should suit your needs.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

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

    Works, but in a different way.

    The above referenced script worked fine, but it's not using the UPS XML server. The solution is good for me but I'm still left feeling a little curious as the better and newer services will be using the XML server.

    Any further thoughts would be appreciated.

    Thanks,
    Bernn

  4. #4
    SitePoint Enthusiast justjeni's Avatar
    Join Date
    Jun 2001
    Location
    USA
    Posts
    59
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    OH my

    Am I out of my league in here! Whoops!
    http://www.justjeni.com

  5. #5
    SitePoint Member
    Join Date
    Jun 2001
    Posts
    11
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm coming to this thread a bit late, but perhaps someone is still reading...?

    I tried the script recommended by freddydoesphp, and I was thrilled to find it because it's just what I was hoping for. Unfortunately when I tested it I found that the quote that it returned was not the same as the quote i'm finding by entering the same data (origin, destination, weight etc.) on the UPS site's rate calculator page.

    Has anybody encountered this problem?

    Any idea why this happens????

    thanks much,
    john

    Originally posted by freddydoesphp
    Bernn

    Check out this script.
    http://px.sklar.com/code-pretty.html?code_id=244

    Its a php class for getting UPS shipping costs and should suit your needs.


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
  •