Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Delphi application needs to upload a file to a webserver

760 views
Skip to first unread message

Michael Adamovic

unread,
Mar 23, 2001, 9:46:05 AM3/23/01
to
I've the problem that i cannot connect to a interbase database from an
delphi application directly, because a firewall does'nt open the port 3050.
So I would like to send the database file using HTTP-Protocol. FTP is also
not available.
The only way to upload a file I found, is to create a HTML page using <form>
</form>. But the user should not fill in the form, the application should do
that.
I don't know how ?

Can anybody help.


Michael


Mike Rochette

unread,
Mar 24, 2001, 10:03:58 AM3/24/01
to
Off the top 3 solutions come to mind;
-Use Midas to transmit your database entries
-Make an Isapi DLL that will handle the transfer on port 80
-post the file as a uencode or base 64 text stream to a com object
that will know what to do with it.

David Broadfoot

unread,
Mar 25, 2001, 7:37:12 AM3/25/01
to
http://www.tmssoftware.com offer TWebCopy that does downloads - perhaps you
can modify it to do uploads. You can always search www.torry.net for such
things too (search for 'web'.)

David


Michael Adamovic <michael....@absthessen.de> wrote in message
news:99fnh5$d48$02$1...@news.t-online.com...

Jordi Rovira

unread,
Mar 26, 2001, 5:29:09 AM3/26/01
to
I found this aricle on Borland Code Central :


<font size="+2">Automating Internet Explorer to POST Form Data</font><br>
<a href="mailto:cd...@borland.nospam.com">By Corbin Dunn</a><br>
Delphi Developer Support<br>

<P>This document is based on an example from the MSDN: <a
href="http://support.microsoft.com/support/kb/articles/Q167/6/58.ASP">HOWTO:
Automate Internet Explorer to POST Form Data</a>. It shows the Delphi way of
POSTing form data.

<P>It is easy to automate Internet Explorer (IE) to send data using the POST
method to any web server. This example illustrates automation of Internet
Explorer (TWebBrowser) while it is embedded inside of the application, but
it could easily be not shown and hidden from the user.

<P>Internet Explorer versions 3.0, 3.01, and 3.02 do not support posting
data
to an HTTP server via the Navigate method. WinInet and URL Monikers are two
possible alternatives. For more information on WinInet and Monikers, visit
these articles on the MSDN: <A
HREF="http://support.microsoft.com/support/kb/articles/Q165/2/98.ASP">Q16529
8 - HOWTO: Simulate a Form POST Request Using WinInet</A> and <A
HREF="http://support.microsoft.com/support/kb/articles/Q165/8/00.ASP">Q16580
0 - SAMPLE: Using a URL Moniker to POST Data</A>.
<br>
<br>
To test the example below, the following Active Server Page (ASP) should
be saved to the file navpost.asp in a directory on Windows NT 4 or 2000
machine
running at least Internet Information Server (IIS) version 3.0. The
directory
should be recognized by IIS as a virtual root with execute permission:
<br>
<br>

<blockquote>
<table bgcolor="#E2E2E2">
<tr><td>
<PRE>

&lt;HTML&gt;
&lt;%
cFlavor = Request("Flavor")
cName = Request("FName")
%&gt;
&lt;BODY&gt;
Hello, &lt;% =cName %&gt;. &lt;br&gt;
One scoop of &lt;% =cFlavor %&gt; coming right up!&nbsp;&nbsp;
&lt;/BODY&gt;
&lt;/HTML&gt;</PRE></td></tr></table>
</blockquote>

<P>
1. Create a new application with Delphi<br>
2. Add two TLabel's, a TEdit, TComboBox, TWebBrowser and a TButton to the
form with names and a layout similar to what is shown below:<br><br>
<img src="form_shot.gif" width="600" height="369" alt="Form Screen Shot"
border="0">
<br>
In the TComboBox, add several flavors to the Items.
<br>
3. Under the implementation section of the form, add "uses HTTPApp;".
HTTPApp contains the HTTPEncode function used to url-encode strings.
<br>
4. Double click on the TButton and add the following code to the OnClick
event handler (I named my button btnSubmit):<pre
class="sourcecode"><code><b>procedure</b> TForm1.btnSubmitClick(Sender:
TObject);
<b>var</b>
EncodedDataString: <b>string</b>;
PostData: OleVariant;
Headers: OleVariant;
I: Integer;
<b>begin</b>
<font color="#003399"><i>// First, create a URL encoded string of the
data</i></font>
EncodedDataString := <font color="#9933CC">'FName='</font> +
HTTPEncode(edtFirstName.Text) + <font color="#9933CC">'&amp;'</font> +
<font color="#9933CC">'Flavor='</font> + HttpEncode(cmbxFlavor.Text);
<font color="#003399"><i>// The PostData OleVariant needs to be an array
of bytes as large</i></font>
<font color="#003399"><i>// as the string (minus the NULL
terminator)</i></font>
PostData := VarArrayCreate([0, Length(EncodedDataString) - 1], varByte);
<font color="#003399"><i>// Now, move the Ordinal value of the character
into the PostData array</i></font>
<b>for</b> I := 1 <b>to</b> Length(EncodedDataString) <b>do</b>
PostData[I-1] := Ord(EncodedDataString[I]);
Headers := <font color="#9933CC">'Content-Type:
application/x-www-form-urlencoded'</font> + #10#13;
<font color="#003399"><i>// Finally, we just Naviagte to the URL. Note
that you may have to modify</i></font>
<font color="#003399"><i>// the path to your ASP page's
location.</i></font>
WebBrowser1.Navigate(<font
color="#9933CC">'http://localhost/scripts/navpost.asp'</font>, EmptyParam,
EmptyParam, PostData, Headers);
<b>end</b>;</code></pre>

<P>You should now be able to run the application and see the results.

Michael Adamovic <michael....@absthessen.de> escribió en el mensaje de
noticias 99fnh5$d48$02$1...@news.t-online.com...

Jordi Rovira

unread,
Mar 26, 2001, 5:28:17 AM3/26/01
to
I found thies code in Borland Code Central. Because the News server not
allow
to attatch files, I cut & paste all HTML file.

Cut from here :
*******************************************


***********************************************************
to here
Copy&Paste to a new file ana rename to HTML to view.

Good Lucky !!

Michael Adamovic <michael....@absthessen.de> escribió en el mensaje de
noticias 99fnh5$d48$02$1...@news.t-online.com...

Jordi Rovira

unread,
Mar 26, 2001, 5:30:47 AM3/26/01
to
I found this article in Borland Code Central. Good lucky.

***********************************************************************


Automating Internet Explorer to POST Form Data

By Corbin Dunn
Delphi Developer Support

This document is based on an example from the MSDN: HOWTO: Automate Internet
Explorer to POST Form Data. It shows the Delphi way of POSTing form data.

It is easy to automate Internet Explorer (IE) to send data using the POST
method to any web server. This example illustrates automation of Internet
Explorer (TWebBrowser) while it is embedded inside of the application, but
it could easily be not shown and hidden from the user.

Internet Explorer versions 3.0, 3.01, and 3.02 do not support posting data


to an HTTP server via the Navigate method. WinInet and URL Monikers are two
possible alternatives. For more information on WinInet and Monikers, visit

these articles on the MSDN: Q165298 - HOWTO: Simulate a Form POST Request
Using WinInet and Q165800 - SAMPLE: Using a URL Moniker to POST Data.

To test the example below, the following Active Server Page (ASP) should be
saved to the file navpost.asp in a directory on Windows NT 4 or 2000 machine
running at least Internet Information Server (IIS) version 3.0. The
directory should be recognized by IIS as a virtual root with execute
permission:


<HTML>


<%
cFlavor = Request("Flavor")
cName = Request("FName")
%>

<BODY>
Hello, <% =cName %>. <br>
One scoop of <% =cFlavor %> coming right up!
</BODY>
</HTML>


1. Create a new application with Delphi

2. Add two TLabel's, a TEdit, TComboBox, TWebBrowser and a TButton to the
form with names and a layout similar to what is shown below:

In the TComboBox, add several flavors to the Items.

3. Under the implementation section of the form, add "uses HTTPApp;".
HTTPApp contains the HTTPEncode function used to url-encode strings.

4. Double click on the TButton and add the following code to the OnClick
event handler (I named my button btnSubmit):

procedure TForm1.btnSubmitClick(Sender: TObject);
var
EncodedDataString: string;


PostData: OleVariant;
Headers: OleVariant;
I: Integer;

begin


// First, create a URL encoded string of the data

EncodedDataString := 'FName=' + HTTPEncode(edtFirstName.Text) + '&' +
'Flavor=' + HttpEncode(cmbxFlavor.Text);


// The PostData OleVariant needs to be an array of bytes as large

// as the string (minus the NULL terminator)

PostData := VarArrayCreate([0, Length(EncodedDataString) - 1], varByte);

// Now, move the Ordinal value of the character into the PostData array

for I := 1 to Length(EncodedDataString) do


PostData[I-1] := Ord(EncodedDataString[I]);

Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;


// Finally, we just Naviagte to the URL. Note that you may have to modify

// the path to your ASP page's location.

WebBrowser1.Navigate('http://localhost/scripts/navpost.asp', EmptyParam,
EmptyParam, PostData, Headers);
end;


You should now be able to run the application and see the results.

***********************************************************************


Jordi Rovira

Michael Adamovic <michael....@absthessen.de> escribió en el mensaje de
noticias 99fnh5$d48$02$1...@news.t-online.com...

Jordi Rovira

unread,
Mar 26, 2001, 5:33:28 AM3/26/01
to
I found this article on Borland Code Central.

In the TComboBox, add several flavors to the Items.

****************************************************


Jordi Rovira

Michael Adamovic <michael....@absthessen.de> escribió en el mensaje de
noticias 99fnh5$d48$02$1...@news.t-online.com...

Michael Adamovic

unread,
Mar 27, 2001, 8:22:25 AM3/27/01
to
Thanks for your help.

I will try it with the examples i found in Delphi.

Michael

Mike Rochette <sup...@ofcourseremovethispartbytewise.tv> schrieb in im
Newsbeitrag: 3abcc5b2...@24.64.2.57...

Michael Adamovic

unread,
Mar 27, 2001, 8:23:29 AM3/27/01
to
Thanks David,

I think I first try using MIDAS. If this will not help / work I try to
change this component.

Michael

David Broadfoot <da...@synax.com.au> schrieb in im Newsbeitrag:
99kook$3no$1...@bugstomper.ihug.com.au...

Michael Adamovic

unread,
Mar 27, 2001, 8:25:04 AM3/27/01
to
Thank you Yordi,

I don't like using Internet Explorer ActiveX control in my application. So I
think i first try using MIDAS.


Michael

Jordi Rovira <NOS...@rcorp.grn.es> schrieb in im Newsbeitrag:
99n1k3$o8k$2...@diana.bcn.ttd.net...

0 new messages