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: = '
'
'
' Html>';
Ress: = format
'Http / 1.0 200 ok' # 13 # 10
'Content-Type: Text / HTML' # 13 # 10
'Content-Length:% D' # 13 # 10
'Content:' # 13 # 10 # 13 # 10 '% s', [Length (RESSTR), RESSTR]);
Strlen: = Length (RESSTR);
Ecb.WriteClient (Ecb.connid, Pointer (RESSTR), STRLEN, 0);
Result: = hse_status_success;
END;
If you send a request to this DLL, you will get a response from a page:
Test Server Results
Hello from Isapi