Inserting Input data into a HTTP post.

Discussion in 'XML' started by Geoff, Jun 10, 2004.

  1. Geoff

    Geoff Guest

    I have been asked to add postal rates to a web page shopping cart checkout
    procedure. After contacting the post office I discovered that they used XML
    to receive postal rate requests and send back the rate for a certain size,
    "from:" address, "To:" address and delivery service speed. The examples
    they showed used a HTML "Text Area" and a HTTP post statement to send the
    request however I need to use input from an input box and then insert this
    information into the HTTP post. I have tried using variables but they are
    sent literally rather than being substituted with the information from the
    input statements. Is there a way to include the variable information as
    part of the post? I am new to XML and would have thought that variable
    substitution should be easy however I had no luck. I have included a
    stripped version of the sample code below:

    <HTML>

    <BODY>
    <script>
    function go()

    {
    document.MyForm.action =
    "http://"+document.Config.IP.value+":"+document.Config.PORT.value
    document.MyForm.submit();

    }
    </script>

    <CENTER><H3>Sample HTTP Request to eParcel</H3></CENTER>
    <FORM name=Config>
    <CENTER>
    Server IP Address <INPUT size = 15 name=IP value="206.191.4.228">
    and port (TCP) <INPUT size=5 name=PORT value="30000">
    </CENTER>
    <CENTER>
    Postal Code: <INPUT size = 6 name=fpc value=""> <!--
    Variable assigned value here -->

    </CENTER>
    <CENTER>
    </FORM>

    <FORM METHOD=POST name="MyForm">
    <CENTER>
    <TEXTAREA NAME=XMLRequest ROWS=20 COLS=80>

    <?xml version="1.0" ?>
    <eparcel>
    <ratesAndServicesRequest>
    <!--**********************************-->
    <!-- Merchant Identification assigned -->
    <!-- by Canada Post -->
    <!-- -->
    <!-- Note: Use 'CPC_DEMO_HTML' or ask -->
    <!-- our Help Desk to change your -->
    <!-- profile if you want HTML to be -->
    <!-- returned to you -->
    <!--**********************************-->
    <merchantCPCID> 1234 </merchantCPCID>

    <!--*********************************-->
    <!--Origin Postal Code -->
    <!--This parameter is optional -->
    <!--*********************************-->
    <fromPostalCode> t6a0h9 </fromPostalCode>

    <postalCode> VARIABLE NEEDS TO GO HERE(fpc) </postalCode>
    </ratesAndServicesRequest>
    </eparcel>
    </TEXTAREA>

    <BR><BR>
    <INPUT TYPE=SUBMIT VALUE="Submit XML request to eParcel via HTTP/POST"
    onClick="go()">
    </CENTER>

    </FORM>

    <BR><BR><BR>

    </BODY>
    </HTML>
    Geoff, Jun 10, 2004
    #1
    1. Advertising

  2. Geoff wrote:

    > I have been asked to add postal rates to a web page shopping cart checkout
    > procedure. After contacting the post office I discovered that they used XML
    > to receive postal rate requests and send back the rate for a certain size,
    > "from:" address, "To:" address and delivery service speed. The examples
    > they showed used a HTML "Text Area" and a HTTP post statement to send the
    > request however I need to use input from an input box and then insert this
    > information into the HTTP post.


    As long as you use a HTML page and want to post data to a server you
    simply need to learn HTML and how use forms to post data:
    <form action="whatever"
    method="post">
    <input type="text" name="from">
    <input type="text" name="to">
    ...
    <input type="submit">
    </form>

    Your code that you had below seems to rely on JavaScript to simply
    submit a form which doesn't make sense as HTML can do that without any
    need for script being supported and enabled in a browser.

    As for the XML in that textarea could you provide a URL of that postal
    service that clearly describes the input format and response format?
    From your email address I guess it is a Canadian postal service, I have
    had some look around on http://www.canadapost.ca/ but all I have found
    is some instructions to apply for a shipping profile account.
    It is also not clear to me whether a client side solution is really
    helpful to you, I would rather expect that you would build a form to
    send data to your own web server and there with some server side
    processing like PHP or ASP you would then request shipping information
    from that postal service server.

    Thus if you provide more information someone here in this group can help
    even if he is not familiar with that particular Candadian postal
    service. But consider to also try a Canadian group, maybe that postal
    service even runs an online forum for customers making HTTP shipment
    requests.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jun 10, 2004
    #2
    1. Advertising

  3. Geoff

    Geoff Guest

    Thanks so much for your reply Martin.

    Here is a link to Canada Post - Sell Online Developer's Site :

    http://206.191.4.228/DevelopersResources/protocolV3/index.html

    Here is a sample page of my shopping cart:

    http://www.hflags.com/demostore/html 2/souvenirs/02.htm

    Although I have built a handful of java based shopping carts and html
    forms generally, this is the first time I've been asked to integrate
    this shipping module from Canada Post into a java based cart.

    There is an asp option which is quite easy. Unfortunately this cart
    resides on a unix based server.

    Of Note:

    "If you use Java: Sun's XML parser"

    http://java.sun.com/xml/ Is this of any help?

    Thanks, Geoff



    *** Sent via Devdex http://www.devdex.com ***
    Don't just participate in USENET...get rewarded for it!
    Geoff, Jun 10, 2004
    #3
  4. Geoff wrote:


    > Here is a link to Canada Post - Sell Online Developer's Site :
    >
    > http://206.191.4.228/DevelopersResources/protocolV3/index.html
    >
    > Here is a sample page of my shopping cart:
    >
    > http://www.hflags.com/demostore/html 2/souvenirs/02.htm
    >
    > Although I have built a handful of java based shopping carts and html
    > forms generally, this is the first time I've been asked to integrate
    > this shipping module from Canada Post into a java based cart.
    >
    > There is an asp option which is quite easy. Unfortunately this cart
    > resides on a unix based server.


    Well, you have to decide what you want and look at what is possible, you
    have much of that shopping cart code in client side JavaScript but
    somehow I think you also have server-side processing. I don't know what
    language you use on the server, whether that is PHP or Perl or Java
    (servlets or JSP). Normally you would build a HTML form for the user to
    enter the shipping details you need and let the user submit that data to
    your server where you process it with the language of your choice and
    built the HTTP request to post to the XML to the postal server which
    gives you a choice as I understand whether to answer with XML or HTML.
    They have provided that form at
    http://206.191.4.228/DevelopersResources/protocolV3/HTTPInterface.html
    as an example to outline the XML to be sent but it clearly says

    Normally, when you integrate eParcel into your website, this XML request
    has to be sent by YOUR server (not by the consumer's browser)

    so you do not need to worry on XML in a textarea or text input, your
    clients should only see a form to enter the shipping details you need,
    submit them with a normal HTML form to your server where you then have
    to build the XML to post it to the Canada postal server.
    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Jun 10, 2004
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bhavesh
    Replies:
    0
    Views:
    413
    Bhavesh
    Jul 16, 2007
  2. Bhavesh
    Replies:
    5
    Views:
    608
    Bhavesh
    Jul 18, 2007
  3. Bhavesh
    Replies:
    1
    Views:
    442
    Bhavesh
    Jul 17, 2007
  4. Renie83
    Replies:
    1
    Views:
    169
    Kiran Math
    Jul 10, 2003
  5. cerr
    Replies:
    1
    Views:
    121
    Piet van Oostrum
    Aug 16, 2013
Loading...

Share This Page