Delphi and internet2

zhaozj2021-02-17  49

Delphi and internet2

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

Wininet: Build an FTP, HTTP, and Gopher User-end program ISAPI: Expand Internet information services, for example, get information on the server and display them on the browser.

In today's computer world, a huge development trend is set off due to Microsoft's Internet strategy. Those production

The days of CGI (public gateway interface) and third-party tools (even the most basic Internet tool) will eventually go back. The need for complex third-party tools always exists, but now the programmer will find the large amount of Internet tools they need, in short, do not need further investment, you can use free Delphi resources come:

* Develop web browser

* Run FTP, HTTP, and GOPHER, between two Delphi applications or Delphi applications and TCP

(Transfer Control Protocol) operation TCP

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

Slightly the right to cooperate with our plan. 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 a short description of the technical information mentioned in this article, and a short description of the hardware and software that you need.

* 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 an Internet information service document 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 download from Microsoft's 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 part of this article, the second unit

The machine must be able to run all software supporting web browsers. If you run on your machine, Windows 95 or Windows NT

Then the Wininet Codes in this article can run the best. Any eligible web browser can be used in this technical environment.

In the version released by Delphi 2.0 after June 1996, you need to connect Delphi to the Internet.

Almost all resources.

If you don't have the latest Delphi version [Note: The author refers to version 2.0 (translator)], then you need this article.

Special documents mentioned in the file, all of these can be available for free from the World Wide, if you are using Delphi 2.0 or higher, you are not allowed to consider (translator)]. All the techniques mentioned herein can work smoothly in the Delphi2.0 environment, but it will not work well in the 16-bit Delphi environment.

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

Ndex.html

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

The new version of Delphi2.0 is accompanied by Wininet.Pas documentation. If your copy does not contain it, then the above World Wi-Net Node can provide you. Wininet.Pas includes variable lists, functions, types, and properties designed to extend Microsoft Windows Internet. This means you can easily add FTP, HTTP, and Gopher support for your application easily. Microsoft's Wininet.dll is free. If it is not in your Windows / System or Windows / System32 directory, you can get it from Microsoft. Here is the World Wide Web Node for Wininet.h 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 Microsoft's documentation

The technique described, this technology enables you "'Write the' server-side original and filtering this to expand 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 be in Delphi

Drag and drop them on the application (these controls are included in Delphi2.0). They provide instant support for creating a Delphi application, they know how to browse the web, how to apply FTP, Winsock, and other Internet technologies. If you do not include these controls in your Delphi copy, you should add these documents to the lib directory in the directory where Delphi is located. These documents are located under the INDEX.html site in the Borland's Borland. 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 very familiar with Delphi and Object Pascal, and the reader is for the Internet, HTML,

Browser and World Wide Web server have basic understanding.

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 WindowsNT 4.0 to create web, ftp, and gopher sites on your server. At the same time, this technology is related to WindowsNT3.51 Server [Note: Refers to the server version, and the other version is a workstation version (translator)] compatible.

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

Limited by their implementation [Note: If Perl is explained (translator)]. When you send a CGI-based request to the server from browsing, this CGI application will be very likely to be mandated first, which will consume a lot of time. Moreover, in some environments, CGI technology seems to be a bit slightly.

ISAPI is a method of replacing CGI applications by writing a DLLS [Note: Dynamic Link Program (Translator)]. You can also write filtration text through ISAPI, but I will not mention it in this article. Compared with CGI, ISAPI is easier to use, and it is faster and can better utilize 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 to CGI applications, they can load memory faster; when they issued a request on the server, the time required [Note: Remember the time (translator) of the request to accept the server (translator)] Be less Most. 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 advance when you try to request;

They are not used to uninstall this ISAPI application DLLS to release system resources.

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

With Microsoft documents, you can use ISAPI filter text to do this:

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 returns the data set, or how to enter the browser

Simple contact.

ISAPI foundation

The httpext.pas file contains a key declaration using ISAPI. This document should be published in June 1996

Delphi version distribution. It can also be found on the Borland site, and this document is attached to the ISAPI section of this article. Because this is based on NT-based technology, you must use the version of Delphi 2.0 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 composed of C

Write (translator)]. When writing Delphi, there is no ISAPI user interface, I will only describe how to use Microsoft's existing technology. However, ISAPI is 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 in the Delphi application

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, do this

Two functions are the key to all ISAPI programming.

These three statements contain "word output", using this term is because ISAPI DLLS expands the Internet information service

. (Remember, the Internet Information Server refers to Microsoft Server. If you want to use a NT server as a physical web server, then this is the tool you need. SisaPi DLLS with NT4.0 distribution, in installation operating system It is automatically installed.)

ISAPI provides a standard that makes a server that can be followed. For example, it can interface the complex NSAPI interface of the Netscape Company

Compressed to related concise and beautiful ISAPIs to operate 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. The two variables in the record are "self-declared", the previous version containing the version number [Note: That is, the variable DWEXTensionVersion (Translator)], the latter represents a string for user-defined to describe the DLLS.

While you refer to the getExtensionVersion statement, you must add to the DPR file section of your DLL program.

Part. When you write this statement, you should also write:

Exports

GetExtensionVersion

HTTPEXTENSIONPROC;

This is what you have to do when you build these two important Isapi DLL functions. Next, use HTTPEXTensionProc, a little complicated, so I will use 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

Begin ... End section in Delphi

Here 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;

RESSTR: = ''

'

TEST Server Results'

'Hello from Isapi'

'';

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)

Runtr]);

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

Most of the domains in the function provides a simple HTML code for basic information. You also need to fill in some of the domains in the TextensionControlblock, as shown below.

Note that there is a function pointer called WriteClient in this record, you can quote this function to pass the information

Send back the browser. When you call this function, you use the ConnID field in the TextensionControl block mentioned below. When a function is called, ConnID is automatically populated for you.

Before viewing the code of the function, let me demonstrate all the HTTPEXTensionProc functions mentioned above.

ISAPI DLL full procedure

Library isapi1;

Library isapi1;

Uses

Windows

Sysutils

HTTPext;

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

Begin

Ver.dWextensionVersion: = $ 00010000; // We're Expecting Version 1.0 Support

Ver.lpszextensionDesc: = 'Written in Delphi 2.0';

RESULT: = TRUE;

END;

Function httpextensionproc (var ecb: textension_control_block): DWORD;

STDCALL;

VAR

Ress: string;

Strlen: Integer;

Begin

ECB.LPSZLOGDATA: = 'DELPHI DLL LOG';

Ecb.dwhttpstatuscode: = 200;

RESSTR: = '

'

'

Test Server Results

'

'

Isapi Says Hello to Devrel

"

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)

Runtr]);

Strlen: = Length (RESSTR);

Ecb.WriteClient (ecb.connid)

Pointer (RESSTR)

Strlen

0);

Result: = hse_status_success;

END;

Exports

GetExtensionVersion

HTTPEXTENSIONPROC;

Begin

End.

In order to run this DLL program, you should copy it to the scripting directory under your NT server. It is like this in my NT4.0 machine:

C: /winnt/system32/inetsrv/scripts/mystuff/isapi1.dll

In this example, I have created my directory called "mystuff".

It is just to store I created.

ISAPI DLLS. Your directory, of course, as unfold on my machine, depends on your "inetsrv" directory location and other factors.

To successfully call this DLL, you should add this hyperlink to your HTML page:

Isapi One

When the user clicks this hyperlink, the Isapi1 DLL will be called, then the string "Hello from Isapi" will show

Show on the user's browser. If you are not putting Isapi.dll in mySTuff directory, you should modify the above HTML code to adapt it to you. Note that your directory must be related to the directory inetsrv, should not, and cannot include the directory where your entire DLL is located.

Here is the complete HTML script of the call:

My Home Page

This is the home page for my home computer.

Isapi One

Note that if you copy the program isapi1.dll multiple times to the MySTuff directory, you should be before copying.

Turn off the web server of the web server. This is because when you copy this DLL for the first time, you can not be restricted, but after this, it belongs to the server. Therefore, when you copy the updated version of the first copy, you turned off the World Wide Web service. You can use the network management program to turn off the World Wide Web service. This program should be installed under Explorer / Program Manager when installing a network information service in Microsoft Internet Server Group.

Work with TextensionControlblock

Through this point in this article, you can build your first ISAPI DLL and can be on the second machine

Page browser calls it.

The rest of the ISAPI in this article will be more deeper.

Here is a complex part of the HTTPEXTensionProc parameter

PextensionControlblock = ^ TextensionControlblock;

TextensionControlblock = Packed Record

Cbsize: dword; // = sizeof (TextensionControlblock)

DWVersion: DWORD; // Version Info of this Spec

Connid: hconn; // context do not motify!

DWHTTPSTATUSCODE: DWORD; // http status code

// Null Terminated log Info Specific To this Extension DLL

LPSZLOGDATA: Array [0..hse_log_buffer_len-1] of char;

LPSZMETHOD: PCHAR; // Request_method

LPSZQUERYSTRING: PCHAR; // Query_String

LPSZPATHINFO: PCHAR; // PATH_INFO

LPSZPATHTRANSLATED: PCHAR; // PATH_TRANSLATED

CBTOTALBYTES: DWORD; // Total Bytes from Clom Clom Clism

CBAVAILABLE: DWORD; / / AVAILABLE NUMBER OF BYTESLPBDATA: POINTER; / / POINTER TO CBAVAILABLE BYTES

LPSZCONTENTTYPE: PCHAR; // Content Type of Client Data

GetSerVariable: TgetSerVariableProc;

WriteClient: twriteclientproc;

Readclient: TreadClientProc;

ServersupportFunction: TSERVERSUPPORTFUNCTIONPROC;

END;

Note that this record contains the ConnID field mentioned above and transmits the first parameter to WriteClient.

The first parameter in this record is set for version control. It should be the specification of the size of TextensionControlblock. If Microsoft has changed its structure, they can determine the structural version they are processing by checking the size of records. You will never be the first three fields in this record, they have already been filled by ISAPI, in your program, they can only be accessed, and cannot be changed.

The most important field in this record may be lpszqueryString, which contains requests from the server

Information. For example, suppose you have created a named ISAPI1.DLL. To call this DLL, you have to create a href like this on a page of your browser (Note: A format in the HTML language]:

Test One

If you want to respond to this DLL, you have to do this for the above line:

Test One

If there is a second line in the HTML code segment, then your DLL will be in the lpszquerystring parameters.

Get the string of "myQuery", especially pay attention to the use of the request flag after the request string.

Of course, you can change the request string as you want. For example, you can write this:

Test One

In this request, this DLL answers the name of the server. You are not subject to any restrictions when passing this parameter. you

You can pass anything you want, and how to analyze the information in the DLL is also determined by your preferences.

When you return information from the server to the browser, you use the "WriteClient" function pointer in this record

. You don't need to do anything when you initialize this pointer; it has automatically passed to you.

The author of the CGI app will notice the syntax of the transfer request string is very familiar. In fact, ISAPI follows CGI

Most habits, most fields in TextensionControlBlock can be borrowed simply by CGI technology.

Another key field in TextensionControlBlock is lpbdata, which contains additional information from browsing.

For example, you have an HTML form accompanying a few fields, which are called by the information.

LPDATA "pointer delivery. The next topic in this article" "Getting information from 'confirm the' button" will focus on how to handle this situation.

I have already introduced four key fields in TextensionControlblock now:

WriteClient: An HTML data that allows you to deliver a formatted HTML to your browser. This function is used

TextensionControlBlock's connid field.

LPSZQUERYSTRING: From the request from the browsing ride.

LPBDATA: Additional data from the person from the browser. Usually the content of any field of an HTML form

. I will discuss this part of the Confirm Button.

To get the fields in other TextensionControlblock, the best way is to personally browse them to do it. In other words, you will want to create an HTML page so that you can call the client's ISAPI DLL. The purpose of this ISAPI DLL is to be in the format of TextensionControlblock in HTML, and then pass them back into the browser. This will turn your browser into a alarming debugger to display all the fields in the TextensionControlblock.

Here is a program, written by Borland's Danny Thorpe, he will perform this task:

Library Test1;

Uses

Windows

Sysutils

HTTPext;

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

Begin

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

Ver.lpszextensionDesc: = 'a test dll Written in delphi 2.0';

RESULT: = TRUE;

END;

Function HTTPEXTensionProc (var ECB: Textension_Control_block):

DWORD; stdcall;

VAR

Ress: string;

Strlen: Integer;

BUF: array [0..1024] of char;

Begin

ECB.LPSZLOGDATA: = 'DELPHI DLL LOG';

Ecb.dwhttpstatuscode: = 200;

Ress: = format

''

'

TEST Server Results'

'Size =% d'

'Version =% .8x'

'Connid =% .8x'

'Method =% s'

'Query =% s'

'PathInfo =% s'

'PathTranslated =% s'

'Totalbytes =% d'

'AvailableBytes =% d'

'ContentType =% s'

'

Some Server Variables'

[Ecb.cbsize

ECB.DWVERSION

Ecb.connid

ECB.LPSZMETHOD

Ecb.lpszqueryString

ECB.LPSZPATHINFO

Ecb.lpszpathtranslated

Ecb.cbtotalbytes

ECB.CBAVAILABLE

ECB.LPSZCONTENTTYPE]);

With ecb do

Begin

Strlen: = Sizeof (BUF);

GetSerVariable (ConnID)

'Remote_addr'

@BUF

Strlen);

RESSTR: = RESSTR 'Remote_addr =' BUF '';

Strlen: = Sizeof (BUF);

GetServerVariable (Connid'Remote_host '

@BUF

Strlen);

RESSTR: = RETTR 'Remote_host =' buf '';

Strlen: = Sizeof (BUF);

GetSerVariable (ConnID)

'Remote_User'

@BUF

Strlen);

RESSTR: = RETTR 'Remote_user =' BUF '';

Strlen: = Sizeof (BUF);

GetSerVariable (ConnID)

'Server_name'

@BUF

Strlen);

R: = RESSTR 'Server_Name =' BUF '';

Strlen: = Sizeof (BUF);

GetSerVariable (ConnID)

'Server_Port'

@BUF

Strlen);

RESSTR: = RESSTR 'Server_Port =' BUF '';

Strlen: = Sizeof (BUF);

GetSerVariable (ConnID)

'Server_Protocol'

@BUF

Strlen);

R: = RESSTR 'Server_Protocol =' BUF '';

Strlen: = Sizeof (BUF);

GetSerVariable (ConnID)

'Server_software'

@BUF

Strlen);

R: = format ('% sserver_software =% s'

'Threadid =% .8x'

[Relasstr

BUF

GetCurrentThreadId]);

END;

RESSTR: = relasstr ​​ ';

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)

Runtr]);

Strlen: = Length (RESSTR);

Ecb.WriteClient (ecb.connid)

Pointer (RESSTR)

Strlen

0);

Result: = hse_status_success;

END;

xports

GetExtensionVersion

HTTPEXTENSIONPROC;

Egin

End.

In order to call this DLL, you should create a HRML script including the following line.

Test One

Get information from the Confirm button

There is a confirmation button in an HTML form that is usually sent to you. As long as the amount of information is less than 49kb, you can

The lpbdata fields in TextensionControlblock are only available. Here shows how you can

In most cases, get information sent by this field: VAR

String;

Begin

...

S: = pchar (ecb.lpbdata);

...

END;

If the information from this field is greater than 48KB, then you must call readclient to get the rest of the information.

If you want to know which information in the lpbdata field is available, you can use the following two functions to transfer the data back to your web browser:

Function setupresstring: String;

Begin

Result: = ''

''

'

TEST Server Results'

'lpbdata =% s'

'';

END;

Function HTTPEXTensionProc (Var ECB: TextensionControlblock):

DWORD; stdcall;

VAR

Ress: string;

Strlen: Integer;

S

S1: STRING;

Begin

ECB.LPSZLOGDATA: = 'DELPHI DLL LOG';

Ecb.dwhttpstatuscode: = 200;

Ress: = setupresstring;

S: = pchar (ecb.lpbdata);

RESSTR: = Format (RESSTR

[S]);

Strlen: = Length (RESSTR);

Ecb.WriteClient (ecb.connid)

Pointer (RESSTR)

Strlen

0);

Result: = hse_status_success;

END;

Suppose you already have an HTML form with the following code:

This code will generate a form that contains a text to enter a number and a form called "submit" button, the name of the button is called "getSquare". If there is this form, you can then expect the above two programs to return the following string, assume the user in the text area in the form, edited the number 23:

lpbdata = getsquare = 23 & getSquare = Submit

In order to understand what happened this, pay attention to the main part of the HTML statement from the above function, this part of the statement resides on the server, reflected as follows:

'lpbdata =% s'

If you have studied the code in the HTTPEXTensionProc function, you will find that it will use the% s parameters in the Format statement before this sentence instead of the value in ecb.lpbdata. (If you don't know how the statement format works, please refer to the Delphi documentation) [Note: Delphi2 programming in the author (Delphi2)

Chapter 3, "String and Text File" in Unleashed, "Translator)]

Assuming the above in the form, the value of LPBData is transmitted to the ISAPI DLL when the user presses the "Confirm" button is:

Getsquare = 23 & getsquare = Submit

In order for you to have a clear concept, let me repeat the information that the above two statements passed back to the browser is the string below, you have seen:

lpbdata = getsquare = 23 & getSquare = Submit

The best way to watch this process tries to run the ISAPI2 program listed below. Isapi2 and ISAPI1 are almost, but he contains the new HTTPEXTensionProc function above, and it also contains the setupresstring utility. Library isapi2;

Uses

Windows

Sysutils

HTTPext;

Function getExtensionVersion (VAR Ver: THSE_VERSION_INFO):

Bool; stdcall;

Begin

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

Ver.lpszextensionDesc: = 'DLL Written in Delphi 2.0';

RESULT: = TRUE;

END;

Function setupresstring: String;

Begin

Result: = ''

''

'

TEST Server Results'

'lpbdata =% s'

'';

END;

Function HTTPEXTensionProc (var ECB: Textension_Control_block):

DWORD; stdcall;

VAR

Ress: string;

Strlen: Integer;

S

S1: STRING;

Len: integer;

Begin

ECB.LPSZLOGDATA: = 'DELPHI DLL LOG';

Ecb.dwhttpstatuscode: = 200;

Ress: = setupresstring;

S: = pchar (ecb.lpbdata);

RESSTR: = Format (RESSTR

[S]);

Strlen: = Length (RESSTR);

Ecb.WriteClient (ecb.connid)

Pointer (RESSTR)

Strlen

0);

Result: = hse_status_success;

END;

Exports

GetExtensionVersion

HTTPEXTENSIONPROC;

Begin

End.

Once you get information from the LPBDATA variable from the form, you can analyze this information or return them to the user. For example, you can draw the number 23 from the above example and return to the user square. By doing this, you can get information from the user, here is a number, some mathematical operations for numbers, and finally returns the result to the user. This means you can create an interactive web page in the radio wave, this is the most popular in the Internet programming!

The following is a complete program code for the browser through the network:

Library isapi3;

{This code shows how to take Input from the user via a broment

Parse That Information

And the return an afflicl to the user. in pieicular

The user submits a number

This Code Squares IT

And the result back to user. Here is the form from the broment: Submits the information for Parsing:

}

Uses

Windows

Sysutils

HTTPextStrbox;

Function getExtensionVersion (VAR Ver: THSE_VERSION_INFO):

Bool; stdcall;

Begin

Ver.dWextensionVersion: = $ 00010000; // Version 1.0 Support

Ver.lpszextensionDesc: = 'isapi3.dll';

RESULT: = TRUE;

END;

// Parse lpbdata and retrieve the number the user passed to us.

Function Parsedata (S: String): Integer;

Begin

S: = StriplastToken (s

'&');

S: = StripfirstToken (s

'=');

Result: = STRTOINT (S);

END;

Function setupresstring: String;

Begin

Result: = ''

''

'

TEST Server Results'

'Answer =% d'

'';

END;

Function HTTPEXTensionProc (var ECB: Textension_Control_block):

DWORD; stdcall;

VAR

Ress: string;

Strlen: Integer;

S

S1: STRING;

Num: integer;

Begin

ECB.LPSZLOGDATA: = 'DELPHI DLL LOG';

Ecb.dwhttpstatuscode: = 200;

Ress: = setupresstring;

S: = pchar (ecb.lpbdata);

Num: = parsedata (s);

Num: = SQR (NUM);

RESSTR: = Format (RESSTR

[NUM]);

Strlen: = Length (RESSTR);

Ecb.WriteClient (ecb.connid)

Pointer (RESSTR)

Strlen

0);

Result: = hse_status_success;

END;

Exports

GetExtensionVersion

HTTPEXTENSIONPROC;

Begin

End.

This code accepts the following strings from the user who presses the confirmation button, and the user requires a square number:

Getsquare = 5 & getSquare = Submit

Suppose this input, this code returns the following strings under the Internet:

Answer = 25

In a word, the user enters the number 5, and you return the user number 25. If the user submits the number 10, then you return to the number 100. This looks insignificant, but it is important here that the Internet has occurred on the Internet [Note: Refers to the interactive web page (translation

By)]

Analyze the functions from users like this:

// Parse lpbdata and retrieve the number the user passed to us.

Function Parsedata (S: String): Integer;

Begin

S: = StriplastToken (s

'&');

S: = StripfirstToken (s

'=');

Result: = STRTOINT (S);

END;

These two statements are in the unit, and it is mentioned in this article, which is also included on my site. [Note: This file is almost everywhere on the network.

You can also ask the translator (translator)] [in this article

I just want to talk so much about Isapi. These content should be enough for inspiring you to use this superior technology and have fun. Next, I want to talk about GetServerVariable, ReadClient, in this respect, I only conducted an extremely limited trial. In this article, I have an HTTPEXT.PAS file, because in addition to this key document, you will not find it elsewhere.

GetServerVariable and readclient statements

As requested in your CGI application, you can use statements to get information from the server. Below is an example of calling this statement:

Len: = hsemaxextdllnamelen;

SETLENGTH (S1

Len;

Dec (LEN);

ECB.GetSerVariable (ecb.connid

'Content_length'

PCHAR (S1)

Len;

First, this code sets the length of the buffer that retains the information acquired from the server. Then, it calls the server and issues a request. In this example, it requires "Content_length" of the information from the server.

Microsoft's literature tells us that you can pass the followed strings through the second parameters of GetServerVariable:

Auth_Type It contains the type of authorization. For example, if you use basic (BASIC) authorization, then

The string is "Basic"; if it is NT Challenge response, the string is "NTLM". Other authorized strings are especially corresponding. Because the new authorization type is constantly added to the server, it is not possible to list all possible strings. If the string is empty, then no authorization is used.

The Content_length script is expected to reclaim the number of bytes from the client.

Content_type The content type of information provided by the main body portion of the requesting check. [Note: The younger brother is shallow, A

Post Request is temporarily translated as "Request Break", the hopes of the family refers to (translator)]

Path_info attached routing information provided by the client. It contains roaming roads that follow the URL after the script name

by. If there is, it is in front of the request string.

PATH_TRANSLATED It is the value of Path_info, but includes the name of all virtual routes expanded to a path flag.

Query_string is followed by "?" In the URL of this script.

Remote_addr issues an IP address of a request client or its agent (for example, a gateway or firewall).

Remote_host issues the host name of the requesting client or its agent (for example, a gateway or firewall).

Remote_user contains a username provided by the client and authorized by the server. If you return a null string so user

Make your name (but authorized).

UNMAPPED_REMOTE_USER It is the name of a user with the following characteristics: The user issues a request to the NT user account (this is what he appears as an identity), and the ISAPI application is mapped to the user.

Request_method is an HTTP request method.

Script_name executed script name.

Server_name When it appears in the form of a self-reference URLS, a host name or IP address. Server_Port accepts the port of the requested TCP / IP.

Server_port_secure A string of non-0 is 1. When the request is processed by the security port, it is 1; otherwise it is 0.

Server_Protocol accepts the name and version of the information related to this request-related protocol. He is usually http / 1.0.

Server_software is the name and version of the web server where the ISAPI application DLL program is running. All_http previous variables did not analyze all HTTP field heads. These variables are obtained from the http_ . Field heads (separated by labeling) contain their own strings, which do not terminate.

HTTP_ACCEPT HTTP field header. The received value is: The field is separated by a comma (,). For example: if

Several lines of face are part of the HTTP head:

Accept: * / *, q = 0.1

Then the URL (2.0 new version of the feature) gives its basics.

It should be noted that the information sheet given above is automatically passed by the TextensionControlblock record. because

You don't need to call GetServerVariable. However, if you do have a need, especially if you want to get information from ReadClient and you need to know how much information to read, you can call it.

Many times, you don't need to call ReadClient. However, your browser is greater than 48KB

At the time, you need to call ReadClient to get the rest of the information.

转载请注明原文地址:https://www.9cbs.com/read-30289.html

New Post(0)