Link to home
Start Free TrialLog in
Avatar of bilgehanyildirim
bilgehanyildirim

asked on

Sending XML to A Server Via HTTP Post and parsing the received XML data.

Hi,

I'm trying to develope a software to interact with EPDQ system. I made it work perfectly with php but now I have to do same thing with Delphi.

Main idea is there is an xml string, containing all the necessary information such as amount, credit card number etc. You send it to a server and receive a response again in XML format.

is there any way for doing this with delphi?

PS: This is the PHP code when I sent XML data to server. It might help.

            $ch = curl_init();
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              $Res = curl_exec($ch);
            curl_close ($ch);
Avatar of shaneholmes
shaneholmes

Have you considered using OpenXML?

Use OpenXML combined with (Indy's) TidHTTP to post XML to  web
It works great.


OpenXML is a native Delpih XML solution. Its a set of components used for
manipulating XML. And it is FREE.


Download it here: http://www.philo.de/xml/ 

Indy Components come with Delphi 7 or you can get them here

http://www.indyproject.org/

sholmes



Avatar of Eddie Shipman
Personally, I'd use Microsoft's XMLHTTP object. I used it extensively during my article to connect and communcate with Hotmail.
See it here:
http://www.delphipages.com/news/detaildocs.cfm?ID=137
http://www.delphipages.com/news/detaildocs.cfm?ID=138
and accompanying files here:
http://www.delphipages.com/edit/count.cfm?ID=4615


Here's how I would do it with XMLHTTP:
var
  oXMLDoc:                   IXMLDOMDocument2;
  oXMLHTTP:                  IXMLHTTPRequest;
begin
  oXMLDoc  := CreateOleObject('MSXML2.DOMDocument.3.0') as IXMLDOMDocument2;
  oXMLHTTP := CreateOleObject('MSXML2.XMLHTTP.3.0')     as IXMLHTTPRequest;
  try
    // Populate oXMLDoc with your XML here
    oXMLDoc.Load('xmlfilename');
    oXMLHTTP.open('GET', URL, False,
                  UserName, Password);
    oXMLHTTP.setRequestHeader('Content-Type',
                              'text/xml');
    oXMLHTTP.setRequestHeader('Depth', '0');
    oXMLHTTP.setRequestHeader('User-Agent',
                              USER_AGENT);
    oXMLHTTP.send(oXMLDoc.XML);
     // Get back what the server sent...
    ResponseText := Trim(oXMLHTTP.ResponseText);
    ResponseHdrs := oXMLHTTP.getAllResponseHeaders;
  finally
    oXMLDoc  := nil;
    oXMLHTTP := nil;
  end;  
end;
you can create a web service...Delphi 7 have a good suport for that...
look this site... http://www.drbob42.com/soap/soap42.htm
Sorry, ThoseBug, this is not what he wants to do.
Avatar of bilgehanyildirim

ASKER

EddieShipman,

I couldn't run your example. is there any activex that I need to install?
what problems were you having? no activeX to install, however, did you import the MSXML type lib and place MSXML_TLB in your uses?
I couldn't import MSXML. is the importing MSXML.DLL under windows/system32?
OK. I did install. it works perfect. now can you tell me how I can parse this xml lets say there is

            <Consumer>
                <PaymentMech>
                    <CreditCard>
                        <Expires DataType="ExpirationDate">01/04</Expires>
                        <Number DataType="String">4111111111111111</Number>
                        .
                        .
                        .

I want to get card number (411111111111) and exoiry date (01/04)?
ASKER CERTIFIED SOLUTION
Avatar of Eddie Shipman
Eddie Shipman
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Oh, shoot, forgot expirydate. add this:

    oNodeList := oXMLDoc.selectNodes('//Expires');
    Label2.Caption := oNodeList.item[0].text;

before this:
    oNodeList := oXMLDoc.selectNodes('//Number');
    Label1.Caption := oNodeList.item[0].text;
C'mon EddieShipman.. Do you really want me to open a new question for this?

<Consumer>
  <PaymentMech>
    <CreditCard>
      <Expires DataType="ExpirationDate">01/04</Expires>
      <Number DataType="String">4111111111111111</Number>
    </CreditCard>
  </PaymentMech>
</Consumer>

is only one part of the XML response I receive. Security issues will be solved later. I will open a new question for that, don't worry :))))
Well, I showed you the answer. If there are more than one CreditCard Nodes, then that process won't really work for you because
you have to get the expirydate for each card.

So which would it be, more than one consumer node or more than one creditcard node? I need to know so I can modify the code
to get the expirydate and the corresponding CC#. Do you want this in a stringgrid or stringlist?