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);
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);
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.DO MDocument. 3.0') as IXMLDOMDocument2;
oXMLHTTP := CreateOleObject('MSXML2.XM LHTTP.3.0' ) as IXMLHTTPRequest;
try
// Populate oXMLDoc with your XML here
oXMLDoc.Load('xmlfilename' );
oXMLHTTP.open('GET', URL, False,
UserName, Password);
oXMLHTTP.setRequestHeader( 'Content-T ype',
'text/xml');
oXMLHTTP.setRequestHeader( 'Depth', '0');
oXMLHTTP.setRequestHeader( 'User-Agen t',
USER_AGENT);
oXMLHTTP.send(oXMLDoc.XML) ;
// Get back what the server sent...
ResponseText := Trim(oXMLHTTP.ResponseText );
ResponseHdrs := oXMLHTTP.getAllResponseHea ders;
finally
oXMLDoc := nil;
oXMLHTTP := nil;
end;
end;
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.DO
oXMLHTTP := CreateOleObject('MSXML2.XM
try
// Populate oXMLDoc with your XML here
oXMLDoc.Load('xmlfilename'
oXMLHTTP.open('GET', URL, False,
UserName, Password);
oXMLHTTP.setRequestHeader(
'text/xml');
oXMLHTTP.setRequestHeader(
oXMLHTTP.setRequestHeader(
USER_AGENT);
oXMLHTTP.send(oXMLDoc.XML)
// Get back what the server sent...
ResponseText := Trim(oXMLHTTP.ResponseText
ResponseHdrs := oXMLHTTP.getAllResponseHea
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
look this site... http://www.drbob42.com/soap/soap42.htm
Sorry, ThoseBug, this is not what he wants to do.
ASKER
EddieShipman,
I couldn't run your example. is there any activex that I need to install?
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?
ASKER
I couldn't import MSXML. is the importing MSXML.DLL under windows/system32?
ASKER
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</Exp ires>
<Number DataType="String">41111111 11111111</ Number>
.
.
.
I want to get card number (411111111111) and exoiry date (01/04)?
<Consumer>
<PaymentMech>
<CreditCard>
<Expires DataType="ExpirationDate">
<Number DataType="String">41111111
.
.
.
I want to get card number (411111111111) and exoiry date (01/04)?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Oh, shoot, forgot expirydate. add this:
oNodeList := oXMLDoc.selectNodes('//Exp ires');
Label2.Caption := oNodeList.item[0].text;
before this:
oNodeList := oXMLDoc.selectNodes('//Num ber');
Label1.Caption := oNodeList.item[0].text;
oNodeList := oXMLDoc.selectNodes('//Exp
Label2.Caption := oNodeList.item[0].text;
before this:
oNodeList := oXMLDoc.selectNodes('//Num
Label1.Caption := oNodeList.item[0].text;
ASKER
C'mon EddieShipman.. Do you really want me to open a new question for this?
<Consumer>
<PaymentMech>
<CreditCard>
<Expires DataType="ExpirationDate"> 01/04</Exp ires>
<Number DataType="String">41111111 11111111</ 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 :))))
<Consumer>
<PaymentMech>
<CreditCard>
<Expires DataType="ExpirationDate">
<Number DataType="String">41111111
</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?
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?
ASKER
Sorry, I thought we were still discussing the same question...
Please have a look at
https://www.experts-exchange.com/questions/21380033/Sending-XML-to-A-Server-Via-HTTP-Post-and-parsing-the-received-XML-data-II.html
Please have a look at
https://www.experts-exchange.com/questions/21380033/Sending-XML-to-A-Server-Via-HTTP-Post-and-parsing-the-received-XML-data-II.html
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