Delphi and the internet

zhaozj2021-02-08  260

Delphi and the internet

By Charlie Calvert

Translated by Boen, reprint, please specify: Translate by Boen.

Chinese translation copyright belongs all, use rights belong to CNM programming

"the first"

-------------------------------------------------- ------------------------------

This article mainly tells how to work with Delphi and Internet. Two expertise will be described in this article:

Wininet: Build ftp, http, and gopher user program

ISAPI: Expand Internet Information Services, for example, obtain information on the server and display them on your browser.

In today's computer world, a huge development trend is set off due to Microsoft's Internet strategy. Those making CGIs (public gateway

The days) and third-party tools (even the most basic Internet tool) will eventually do not return. Demand for complex third-party tools

Always exist, but now the programmer will find the Internet tools that they need, in short, not need to be

Step investment, you can use free Delphi resources:

* Develop web browser

* Run FTP, HTTP and GOPHER, between two Delphi applications or Delphi applications and TCP (transmission control protocol)

Operation between servers TCP

Because Delphi can easily call the Windows API, and it supports OCX / ActiveX, so Microsoft's new strategy and our plan cooperation

Just right. Microsoft production tools, and Delphi programmers get harvest!

-------------------------------------------------- ------------------------------

What is it in this article?

This article contains three most and some small parts, three big themes:

* Looking for information: There can be the technical information mentioned in this article, and it contains a shortness of hardware and software about the code in the running text you need.

Description.

* Isapi: How to use ISAPI

* Wininet: How to use Wininet

In most cases, the ISAPI and Wininet parts in this article are completely independent and you can freely choose to read the order.

-------------------------------------------------- ------------------------------

Find information, hardware and software requirements

You need a copy of Microsoft Windows NT 3.51 Server or NT 4.0 Server, which should be attached with Internet Information Services.

Documentation, because you need the technology mentioned in the ramp. This document should be supplied with NT Server 4.0, and the NT 3.51 users can from Microsoft.

Download on the website. Running Windows NT, your machine's minimum configuration should be 486 compatible, more than 20 megabits or more.

You must have another computer with web browsers. In order to make the ISAPI portion in this article, the second machine must be able to run

All software supporting web browsers. If you run on your machine is Windows 95 or Windows NT, then Wininet in this article

The code can run the best. Any eligible web browser can be used in this technical environment.

Among the versions of Delphi 2.0 after June 1996, there is almost all resources that you need to connect Delphi to the Internet.

If you don't have the latest Delphi version [Note: Here the author refers to version 2.0 (translator)], then you need special files mentioned in this document, all of which can be free from the World Wide Website [Note: If You are using Delphi 2.0 or above, you are not allowed

(Translator)]. All the techniques mentioned herein can work smoothly in the delphi2.0 environment, but it is not necessarily available in the 16-bit Delphi environment.

Work well.

If you need to download information from World Wide, link to: http://www.borland.com/techinfo/delphi/index.html

[Note: There is no longer existed now! ((Translator)]

Delphi2.0 is attached to Wininet.Pas documentation, if your copy does not include it, then the above World Wide Node can

Provide you. Wininet.Pas includes variable lists, functions, types, and properties designed to extend Microsoft Windows Internet. This means you can

It is easy to add FTP, HTTP, and Gopher support for your application. Microsoft's Wininet.dll is free, if

It is not in your Windows / System or Windows / System32 directory, you can get it from Microsoft. Below is

Wininet.h, the World Wide Web node for this window help file:

http://www.microsoft.com/intdev/sdk/docs/wininet/default.htm [Note: It's like it! :-( (Translator)]

In general, the online home of Microsoft Internet developers is the INTDEV section of the Microsoft node.

In addition to Wininet and ICP, another key technology supported by Delphi is ISAP. As described in Microsoft's documentation, this technology

Surgery enables you "'Write the original and filtering of the server, thereby expanding Microsoft Internet Information Services and other ISAPI web services."

If you need to find a description of Isapi, you can go:

http://www.microsoft.com/intdev/sdk/servapi.htm [Note: God bless you! ;-) (Translator)]

At the end, a copy of the key ISAPI document called HTTPEXT.PAS is attached.

Microsoft Free Published Internet Control Package (ICP) is an OCX / ActiveX Control Set, you can drag and drop them in Delphi

These controls are included in the program (Delphi2.0). They provide instant support for the creation of a Delphi application, they know how to browse the web,

How to apply FTP, Winsock, and other Internet technologies. If you don't include these controls in your Delphi copy, then you are using them.

You should add these documents to the lib directory in the directory where Delphi is located. These documents are borland in the link mentioned above.

INDEX.HTML site. In this article, I did not mention ICP controls, but anyone who is interested in this technology should clearly confirm that he has these

Copy of the control.

You can download my Pascal application file from my site, and their name is strbox.pas and maathbox.pas.

It is very good to see that the update of this site on this article is very good.

Here I assume that the reader is familiar with Delphi and Object Pascal, and the reader is for the Internet, HTML, browser and Wanwei

There is a basic understanding of the instructor.

ISAPI

Isapi is a very easy to use but powerful technology that allows you to expand the functionality of Internet information services. This technology comes with WindowsNT4.0 to create web, ftp, and gopher sites on your server. At the same time, this technology is with WindowsNT3.51 Server [Note:

The server version, another version is a workstation version (translator)] is compatible.

In the past, the best way to expand web servers is to establish a CGI application. They are powerful tools, but they are also in their implementation format

Restrictions [Note: If Perl is explained (translator)]. This CGI when you send a CGI-based request to the server from browsing

The application will be very likely to be entered into memory first, which will consume a lot of time. Moreover, in some environments, CGI technology is slightly difficult.

A bit.

ISAPI is a method of replacing CGI applications by writing a DLLS [Note: Dynamic Link Program (Translator)]. You can also write through ISAPI

Filter text, but I will not mention it in this article. Compared with CGI, ISAPI is more likely to use, and it is faster and better.

Use system resources. In the following, I will introduce why ISAPI DLLS is more excellent than the CGI application:

ISAPI DLLS and HTTP services are located in the same address, so they can access HTTP services directly from the server. Compared with CGI applications, they

Memory can be loaded faster; when they issued a request on the server, the time required [Note: Remember the request to accept the server response)

Time (translator)] There are few more. This is more important when the load is loaded.

You can control when DLLS is loaded and uninstalled. For example: You can preload DLLs in the first attempt to request; when they are not used, uninstall

This ISAPI applies DLLS to release system resources.

As mentioned earlier, you can use ISAPI to write filter text [Note: Generally referring to scripts (translator) in the C / S structure, more Microsoft documents, you can

Make the following things through ISAPI filter text:

User authorization plan

compression

encryption

Sign in

Communication analysis or other request analysis (for example, looking for "../../etc/password")

In this article, I will focus on how to write DLLs that return the data set, or how to connect with users who run the browser.

ISAPI foundation

The httpext.pas file contains a key declaration using ISAPI. This document should be distributed by Delphi version issued after June 1996. It can also

This document is attached to the ISAPI section of this article with this document in the ISAPI section of this article. Because this is based on NT technology, you must use delphi2.0

The above version is used to apply this technology. You cannot apply it on the 16-bit editor.

HTTPEXT.PAS contains the interface of ISAPI technology created by Microsoft [Note: refers to the Delphi interface, ISAPI is written by C (translator)]. Write

Delphi did not provide ISAPI user interface, I will only describe how to use Microsoft's existing technology. But ISAPI

Too easy to use, and for most users, the version of the user's Delphi object is not necessary.

There are three functions as the entrance of ISAPI DLLs, the first two are required, and the third is optional.

GetExtensionVersion: Introduction to the lowest version

HTTPEXTENSIONPROC: This is the entrance of the DLL, just like the Begin ... End block TerminateExtension: This is an optional program that can be used as a thread that clears other memory allocation.

When you create an Isapi DLL, you must reference the first two functions in the three functions listed above, and perform these two functions is all ISAPIs.

Programming key.

All three statements contain "word output", using this term because ISAPI DLLs expand the Internet information server. (Remember, Internet

The information server refers to a Microsoft server. If you want to use a NT server as a physical web server, then this is what you need.

. ISAPI DLLS distributes with NT4.0 and installing the operating system is automatically installed. )

ISAPI provides a standard that makes a server that can be followed. For example, it can compress the complex NSAPI interface of the Net View to the relevant concise

Beautiful ISAPI operates the NSAPI interface.

Below is the statement of these two important functions

Function getExtensionVersion (VAR Ver: THSE_VERSION_INFO): BOOL; stdcall;

Function HTTPEXTENSIONPROC (VAR ECB: TEXTENSIONCONTROLBLOCK): DWORD; STDCALL;

Just put the getExtensionVersion to your DLLS to save. When ISAPI issues a new version to the public, you only need to make a slight change.

Function getExtensionVersion (VAR Ver: THSE_VERSION_INFO):

Bool; stdcall;

Begin

Ver.dWextensionVersion: = $ 00010000; // 1.0 support

Ver.lpszextensionDesc: = 'delphi 2.0 isapi dll'; // description

RESULT: = TRUE;

END;

The Parameter Passed to this function is deflared in httpext.pas as Follows:

The relevant parameters are declared in httpext.pas:

PHSE_VERSION_INFO = ^ THSE_VERSION_INFO;

THSE_VERSION_INFO = PACKED Record

DWEXTensionVersion: DWORD;

LPSZEXTENSIONDESC: Array [0..hsemaxextdllnamelen-1] of char;

END;

The constant HSEMAXEXTDLNAMELEN is 256 in the statement. These two variables in the record are "self-declaring", the previous one contains

ISAPI version number [Note: That is, the variable DWEXTensionVersion (Translator)], the latter means a user-defined one for describing

DLLS string.

While you reference your getExtensionVersion statement, you must add an output section in the DPR file section of your DLL program. Write in you

You should also write this statement:

Exports

GetExtensionVersion,

HTTPEXTENSIONPROC;

This is what you have to do when you build these two important Isapi DLL functions. Next, use HTTPEXTENSIONPROC, a little complex

I will take it as a separate part.

Work with HTTPEXTensionProc

The HTTPEXTENSITIONPROC statement is the entry of the DLL. Its role is like a main () statement in the C language, or in Delphi

Begin ... End section There is a simple example of using the getExtensionVersion statement

Function HTTPEXTensionProc (Var ECB: TextensionControlblock):

DWORD; stdcall;

VAR

Ress: string;

Strlen: Integer;

Begin

ECB.LPSZLOGDATA: = 'DELPHI DLL LOG';

Ecb.dwhttpstatuscode: = 200;

R: = ' test server result </ title>' </p> <p>'<H1> Test Server Results </ h1>' </p> <p>'<Body> Hello from Isapi <br> </ body>' </p> <p>'</ Html>';</p> <p>Ress: = format</p> <p>'Http / 1.0 200 ok' # 13 # 10 </p> <p>'Content-Type: Text / HTML' # 13 # 10 </p> <p>'Content-Length:% D' # 13 # 10 </p> <p>'Content:' # 13 # 10 # 13 # 10 '% s', [Length (RESSTR), RESSTR]);</p> <p>Strlen: = Length (RESSTR);</p> <p>Ecb.WriteClient (Ecb.connid, Pointer (RESSTR), STRLEN, 0);</p> <p>Result: = hse_status_success;</p> <p>END;</p> <p>If you send a request to this DLL, you will get a response from a page:</p> <p>Test Server Results</p> <p>Hello from Isapi</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-1316.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="1316" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.033</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'CqjvZt1ovG18LVUJqj9cKzsKzjLwZN1P6IhY6fj2iK3TlTE5_2B_2F8YwzzO_2FLUgOfZwI3q_2FtfGfz0bxGQQzLn8Ocg_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>