Internet programming skills 1

zhaozj2021-02-17  48

Internet programming skills

Implement hyperlink

Implement the open browser in the program, the function of opening the mail program first is to join the USES section

Uses shellapi;

Then use the place where the hyperlink is required

SELLEXECUTE (HANDLE)

NIL

Pchar ('Mailto: Guihong@163.net')

NIL

NIL

SW_SHOWNORMAL);

Where Mailtos in Pchar () is to open the mail program, you can replace it with http: //, ftp: //, gopher: //, new: telnet: and so on

Call NetscapeAvigator in Delphi.

As the Internet is hot, have you ever thought about launching the Netscape browser in your Delphi program to display the homepage of the WWW address you specify. The following program can complete this feature.

Programnetscape;

Usesddeman;

Procedurego-Tourl (SURL: String);

VAR

DDE: TDDECLIENTCONV;

Begin

DDE: κTDDECLIENTCONV. Create (nil);

Withddo

Begin

// SpecifyThelocationOfnetScape. EXE

ServiceApplication: κ'c: ιns32ιprogramιιnetscape. EXE ';

// ActivateThenetscapeAvigator

SetLink ('netscape', 'www-activate');

RequestData ('0xffffffff);

// gotothespecifiedurl

SetLink ('Netscape', 'WWW-OpenURL');

RequestData (SURL ', 0xFfffffff, 0x3,, ");

Closelink;

END;

DDE. FREE;

END;

Begin

Gotourl ('http://www.yahoo.com/');

End.

Delphi Development Web Server Program Response User Enter

With the rapid development of Internet / Intranet, there are more and more demand for applications on Internet / Intranet, so Java and ActiveX Form come, but now the bandwidth of Internet is still very low. This CLIENT-based application is very difficult, download a very small, functionally simple Java applet requires a very long time, and there is also a possibility that users do not support this new technology using the browser. In this case, the server-based CGI, Win-CGI, ISAPI / NSAPI is still a major way. Developing a Web Server program using Delphi 3 is very simple, and a large number of components and objects are provided in Delphi 3, supporting the development of the web server program. The routines for simple Web Server program development are provided in DEMOS of Delphi 3. This article is mainly concentrated in this routine.

User input in HTML is mainly, for example, for example (query someone's phone number):

Name:

The Post method is used in this example. So how do you know the user's input information in the Web Server application?

In the HTTP protocol, the client returns data to the Web Server application is mainly through the URL and Content. For example, in the URL: http://www.delphi.com.cn/dfyw/cgi-bin/delinfo.exe? Id = 10, here, ID = 10 data parameters, tell Delinfo.exe display from ID = 10 This is generally used in the case where the amount of data is small, the advantage is that it is easier to enter parameters, and the disadvantage is that the amount of data cannot be too large and affects the display of the URL. The advantage of saving data information in Content does not affect the display of the URL, and the amount of data is large, the disadvantage is that the user can only use the POST method to return data, and other methods are returned by the URL.

There is a TWEBREQUEST object in Delphi. This object analyzes the information returned by HTTP and is very easy to use. For data in Content, TWEBREQUEST uses ContentFields to analyze the data into a TStrings, which can be used directly to use the data ['Name']. The data in the URL, TWEBREQUEST uses QueryFields, and the data analysis is also a TStrings, which can be used directly to read data using request.queryfields.values ​​['name'].

For example, the message processing returned above HTML:

If Request.contentfields.Values ​​['Name'] <'' THEN

Response.content: = request.contentfields.values ​​['name']

'' Phone number is: ' querytelcode (request.contentfields.values ​​[' Name '])

Else

Response.content: = 'Please enter the username';

Establishment of cookies in Delphi 3:

Cookies is a mechanism for web servers in client storage and return information.

This simple, permanent and client-based status information is greatly expanded to web-based client / server (Client / Server) capabilities. So widely used in a large number of practical, such as users who subscribe to Microsoft MSDN, access to Borland Online, and users who have visited my homepage (http://www.nease.net/~borland) Locally stores cookies so that the last record of access is available for next access. Delphi 3 is a visualization, an object-oriented high-efficiency Fast Application Development Tool (RAD) that Borland has been introduced. It provides a large number of latest features, such as developing COM / DCOM, step development ActiveX objects, multi-layer database applications MIDAS Wait, and use Delphi 3 to develop web server-based programs, such as ISAPI / NSAPI, WIN-CGI, and CGI programs are very convenient.

Developing a Web Server program using the Delphi 3 is very simple, because of the use of large amounts of objects such as Web Module, TWEBAPLICATION, TWEBREQUEST, TWEBRESPONSE, TPAGEPREQUEST, TWEBRESPONSE, TPAGEPREQUEST, TWEBRESPONSE, and TPAGEPREQUEST, TWEBRESPONSE, TWEBREQUEST, TWEBRESPONSE

Delphi3 also provides a lot of programs for use

It should be very convenient to TwebResponse.cookies, TwebRequest.cookie, TwebRequest.cookie, Twebrequest.cookiefields, TwebRequest.ExtractCookIEfields, etc. But in order to implement a function, you need to set cookies, but found that the setCookiefIELDS settings provided using Delphi are unsuccessful, and the httpapp.pas and isapiapp.pas files collected by the study Delphi 3 are found in the Chinese Windows 95 and NT environments. This program has an error.

According to NetScape

The format of the cookie should be:

Set-cookie: name = value; expires = data; path = path; domain = domain_name; second

And according to the regulations

Date (DATA) settings must meet the format "WDY

DD-MON-YYYY HH: MM: SS GMT "

Based on RFC822

RFC850

RFC1036 and RFC1123, etc., but check the function tcookie.getHeaderValue in httpapp.pas: String is formatdatetime ('"" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""

Expires);

Where const DateFormat = 'DDD

DD MMM YYYY HH: MM: SS '

The format produced in the English environment is correct in the English environment.

But the results generated in Chinese are not

Because the weeks and months will be represented in Chinese: such as producing "November" in November, this cannot be identified in Netscape Navigator and Microsoft Internet Explorer.

Since the error is that the original VCL does not consider the Chinese environment, the modified method is: 1. Modify the VCL source program, copy the DCU file to the lib directory after compiling, which will completely correct the error, but If you put the source program in another unmodified Delphi (eg, providing the source program to others and reinstall itself), there will be problems. 2, because the use is not much, so the modified program can be placed in its own program, using the TWEBRESPONSE.SETCUSTOMHEADER set by Delphi 3 to set the program in its own program, reload Delphi or in another The results compiled on a computer will also be completely correct. Because of the purpose of cookie, one is used in this session process, not in use, this time does not need an ExpiRES segment, does not generate time error, you can use all cookie programs provided by Delphi 3; another Permanently saved, the longer the time, the better, so you can set the time to February 22, 2099

The method of setting a cookie in the program is:

Response.setCustomHeader ('set-cookie "

'Name = value; expires = sun

22 Feb 2099 08:08:08 gmt '); (Note with your own name, for example, set count = 10, then replace by count, Value uses 10), so you can create a cookie.

The following is a program for accessing a counter, you can refer to:

Const

Lastip: String = '0: 0: 0: 0'; // Avoid repeating count

VAR

String;

Count: integer;

Begin

S: = Request.cookiefIELDS.VALUES ['count'];

IF s <'' Then Begin

Try

Count: = start (s);

Except

Count: = 0;

END;

ELSE COUNT: = 0;

if Lastip Lastip: = Request.RemoteAddr;

Response.setCustomHeader ('set-cookie "

'count =' INTOSTR (count) '; expires = sun

21 Feb 2010 08:08:08 GMT ');

Response.Content: = 'You are the' INTOSTR (count) 'coming to this page!';

END;

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

New Post(0)