Link to home
Start Free TrialLog in
Avatar of moorhouselondon
moorhouselondonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Sending an XML file on a URL

I have an XML file which I have constructed using Delphi 6.  The customer requires this to be transmitted to their customer by means of a URL.  How can this be done from within Delphi 6?  
Avatar of 2266180
2266180
Flag of United States of America image

sending large amount of data via URL is a bad idea. most webservers have a limit on that (dunno for sure what are the limits nowadays)

however you can use the urlencode function defined in idglobal from indy.

cheers
Avatar of moorhouselondon

ASKER

ciuly - thank you for your response.  I hear what you say, the specification is down to my customer's customer's consultants so I'm stuck with this method of transmission.  I will however be splitting up the transmission into small chunks (a typical file would be 8kbytes say).  Something I will need to do is to interpret the response from the remote end that transmission has been successful.

I will have a look at your suggestion later on today.
SOLUTION
Avatar of 2266180
2266180
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
SOLUTION
Avatar of Mohammed Nasman
Mohammed Nasman
Flag of Palestine, State of 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
I've found this,

http://www.matlus.com/scripts/website.dll/Tutorials?DelphiTCPIP&IndyMultiPartFormData&5

but now I'm thinking that I don't have enough information to proceed without speaking to the client.  Posting manually using a browser involves logging in - I need to find out how to incorporate the login details into my request.
I would have thought that the simplest way would be to use the MS XML object and POST the DOM to the URL with content-type="text/xml". The advantage is that the WinINet control handles all the proxying and character translation crap, which with Indy you often have to do by hand.

Import MS XML into Delphi and create an instance of XMLHTTP, use the open method to open the URL, setheader for the content type and send to send the data. See MSDN for further details. Most sites which handle SOAP requests and/or ASP can handle that content-type.

>>I need to find out how to incorporate the login details into my request.

See the documentation, the object handles Basic and NT authorization.
Progress so far:-

I now have a form with an Indy HTTP component on it and, as the site I'm posting to is HTTPS, I have used this in conjunction with the Indy Connection Intercept SSL component.  I have downloaded LIBEAY32.DLL, SSLEAY32.DLL and VSINIT.DLL files.  I now get an error message which says:-

Could Not Load SSL Library

Any thoughts?  I'm quite happy to assign points on the help given so far and start a new question.

I'm hesitant about downloading Indy 10.  Is that likely to be what the problem is, that I'm still using the old Indy?  The reason I'm hesitant is that I do not want to screw apps that I have written that use Indy 9 when I come to re-compile them - is this a problem I will encounter?
Still grappling with this problem.  As part of this saga I have upgraded to Indy 10 and eradicated the old version.  

I alse tried to use TWebbrowser.  This in fact worked successfully with short XML files, but the normal amount of data is too long for Webbrowser to handle (apparently 2048 bytes is the max limit).  Now looking at the possibility of using Wininet.

hSession:=InternetOpen('InetURL:/1.0',INTERNET_OPEN_TYPE_PRECONFIG,nil,nil,0);
hconnect:=internetconnect(hsession,pchar(hostname),INTERNET_DEFAULT_HTTPS_PORT,
                 pchar(susername),pchar(spassword),INTERNET_SERVICE_HTTP,
                 INTERNET_FLAG_EXISTING_CONNECT,0);

The commands above work, but the result returned by the following command is nil.   What am I doing wrong?

hfile:=HttpOpenRequest(hconnect,'POST',pchar(aurl),nil,nil,nil,INTERNET_FLAG_RELOAD,0);


uses msxml2_tlb;

function sendToServer(const ServerUrl : string;
                      const UserName  : string;
                      const Password  : string;
                      const xmlStr    : string) : WideString;
var
   xml : IXMLHTTPRequest;
  begin
   // create the request object
   xml:=CoXMLHTTP.Create;
   // open the URL
   xml.open('POST',ServerUrl,false,UserName,Password);
   // set content-type header
   xml.SetRequestHeader('Content-Type','text/xml');
   // now send the data
   xml.Send(xmlStr);
   // and return the respone from the server
   Result:=xml.responseText;
   xml:=nil;
  end;

Sends the XML string to the server which is EXPECTING an XML Stream.

Alternatively :-
      xml.SetRequestHeader('Content-Type','x-www-form-urlencoded');
      xml.Send('xmlstr=' + xmlStr);

sends the XML string to a CGI script which expects a POST with a variable called xmlstr.

The other problem is, what exactly will the server return? This I need to know so that one can test if the data properly arrived.
Just to keep you in the picture, I am waiting for the specifiers/recipients of this system to schedule in some time when we can sit at our respective pc's to nail this problem.  I have been advised it should be some time this week.  Apologies for the delay.
The method which works (not using Delphi) is to have a web page with a form on it.  The form consists of a text box and a Post button which sends the text in the text box to the destination https url.  The XML is posted as text into the box, then the button is pressed - no buffer overflow problems are apparent (though there must be an upper limit to what can be Posted).  So now I've got to code this up in Delphi.  The recipient will inform us by email of any failures - ha, that's not going to be adequate though (thinking aloud), we need notification of success.
ASKER CERTIFIED SOLUTION
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
Sorry for the delay, we have been having protracted discussions regarding how to represent zero-rated VAT transactions in the XML structure.  

The way this will be done is a variation on BigRat's idea.  So BigRat gets more points, but thank you (and points) also go to Ciuly and Mnasman for your ideas.

Cheers!