Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2005-04-02
13
Medium Priority
?
683 Views
Last Modified: 2010-04-05
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);
0
Comment
Question by:bilgehanyildirim
13 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 13688691
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



0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13698404
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;
0
 
LVL 3

Expert Comment

by:ThoseBug
ID: 13706274
you can create a web service...Delphi 7 have a good suport for that...
look this site... http://www.drbob42.com/soap/soap42.htm
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13706994
Sorry, ThoseBug, this is not what he wants to do.
0
 

Author Comment

by:bilgehanyildirim
ID: 13716933
EddieShipman,

I couldn't run your example. is there any activex that I need to install?
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13718496
what problems were you having? no activeX to install, however, did you import the MSXML type lib and place MSXML_TLB in your uses?
0
 

Author Comment

by:bilgehanyildirim
ID: 13718559
I couldn't import MSXML. is the importing MSXML.DLL under windows/system32?
0
 

Author Comment

by:bilgehanyildirim
ID: 13718757
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)?
0
 
LVL 26

Accepted Solution

by:
Eddie Shipman earned 2000 total points
ID: 13726653
Wouldn't that be another question??

OK, give this a try:

var
  oXMLDoc:                   IXMLDOMDocument2;
  oXMLHTTP:                  IXMLHTTPRequest;
  oNodeList:                 IXMLDOMNodeList;
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;
    // are you sure this is XML formatted correctly?
    // Otherwise you may not get the results you want.
    // See below, the XML I used from your example.
    oXMLDoc.LoadXML(ResponseText);
    oNodeList := oXMLDoc.selectNodes('//Number');
    //oNode := oNodeList.item[0];
    Label1.Caption := oNodeList.item[0].text;
  finally
    oXMLDoc  := nil;
    oXMLHTTP := nil;
  end;  
end;


Does this match the ResponseText that you get back from
the XMLHTTP send?

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

Arer you sure you want to be transmitting unencrypted CC data over an open
line like this? Or is this a secure connection?
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13726675
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;
0
 

Author Comment

by:bilgehanyildirim
ID: 13726726
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 :))))
0
 
LVL 26

Expert Comment

by:Eddie Shipman
ID: 13726789
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?
0
 

Author Comment

by:bilgehanyildirim
ID: 13726853
Sorry, I thought we were still discussing the same question...

Please have a look at

http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21380033.html
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month11 days, 4 hours left to enroll

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question