?
Solved

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

Posted on 2005-04-02
13
Medium Priority
?
646 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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:EddieShipman
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 26

Expert Comment

by:EddieShipman
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:EddieShipman
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:
EddieShipman 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:EddieShipman
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:EddieShipman
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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
Suggested Courses
Course of the Month14 days, 20 hours left to enroll

771 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