📄 ch14.htm
字号:
<BR>
' with the value parts "URL-encoded". The server splits
the key=value<BR>
' pairs at the '&', then spilts the key and value at the '=',
<BR>
' URL-decodes the value string and puts the result into key=value
<BR>
' (decoded) form in the [Form Literal] section of the INI.<BR>
'<BR>
' [Form External]<BR>
' If the decoded value string is more than 254 characters long,
<BR>
' or if the decoded value string contains any control characters
<BR>
' or quote marks the server puts the decoded value into an external
<BR>
' tempfile and lists the field in this section as:<BR>
' key=<pathname> <length><BR>
' where <pathname> is the path and name of the tempfile
containing<BR>
' the decoded value string, and <length> is the length in
bytes<BR>
' of the decoded value string.<BR>
'<BR>
' NOTE: BE SURE TO OPEN THIS FILE IN BINARY MODE UNLESS YOU ARE
<BR>
' CERTAIN THAT THE FORM DATA
IS TEXT!<BR>
'<BR>
' [Form File]<BR>
' If the form data contained any uploaded files, they are described
in<BR>
' this section as:<BR>
' key=[<pathname>] <length>
<type> <encoding> [<name>]<BR>
' where <pathname> is the path and name of the tempfile
contining the<BR>
' uploaded file, <length> is the length in bytes of the
uploaded file,<BR>
' <type> is the content type of the uploaded file as sent
by the browser,<BR>
' <encoding> is the content-transfer encoding of the uploaded
file, and<BR>
' <name> is the original file name of the uploaded file.
<BR>
'<BR>
' [Form Huge]<BR>
' If the raw value string is more than 65,536 bytes long, the
server<BR>
' does no decoding. In this case, the server lists the field in
this<BR>
' section as:<BR>
' key=<offset> <length><BR>
' where <offset> is the offset from the beginning of the
Content File<BR>
' at which the raw value string for this key is located, and <length>
<BR>
' is the length in bytes of the raw value string. You can use
the<BR>
' <offset> to perform a "Seek" to the start of
the raw value string,<BR>
' and use the length to know when you have read the entire raw
string<BR>
' into your decoder. Note that VB has a limit of 64K for strings,
so<BR>
'<BR>
' Examples:<BR>
'<BR>
' [Form Literal]<BR>
' smallfield=123 Main St. #122<BR>
'<BR>
' [Form External]<BR>
' field300chars=c:\website\cgi-tmp\1a7fws.000
300<BR>
' fieldwithlinebreaks=c:\website\cgi-tmp\1a7fws.001
43<BR>
'<BR>
' [Form Huge]<BR>
' field230K=c:\website\cgi-tmp\1a7fws.002
276920<BR>
'<BR>
' =====<BR>
' USAGE<BR>
' =====<BR>
' Include CGI32.BAS in your VB4 project. Set the project options
for<BR>
' "Sub Main" startup. The Main() procedure is in this
module, and it<BR>
' handles all of the setup of the VB CGI environment, as described
<BR>
' above. Once all of this is done, the Main() calls YOUR main
procedure<BR>
' which must be called CGI_Main(). The output file is open, use
Send()<BR>
' to write to it. The input file is NOT open, and "huge"
form fields<BR>
' have not been decoded.<BR>
'<BR>
' NOTE: If your program is started without command-line args,
<BR>
' the code assumes you want to run it interactively. This is useful
<BR>
' for providing a setup screen, etc. Instead of calling CGI_Main(),
<BR>
' it calls Inter_Main(). Your module must also implement this
<BR>
' function. If you don't need an interactive mode, just create
<BR>
' Inter_Main() and put a 1-line call to MsgBox alerting the<BR>
' user that the program is not meant to be run interactively.
<BR>
' The samples furnished with the server do this.<BR>
'<BR>
' If a Visual Basic runtime error occurs, it will be trapped and
result<BR>
' in an HTTP error response being sent to the client. Check out
the<BR>
' Error Handler() sub. When your program finishes, be sure to
RETURN<BR>
' TO MAIN(). Don't just do an "End".<BR>
'<BR>
' Have a look at the stuff below to see what's what.<BR>
'<BR>
'----------------------------------------------------------------------
<BR>
' Author: Robert B. Denny <rdenny@netcom.com>
<BR>
'
April 15, 1995<BR>
'<BR>
' Revision History:<BR>
' 15-Apr-95 rbd Initial release
(ref VB3 CGI.BAS 1.7)<BR>
' 02-Aug-95 rbd Changed to take
input and output files from profile<BR>
'
Server no longer produces long command line.<BR>
' 24-Aug-95 rbd Make call to
GetPrivateProfileString conditional<BR>
'
so 16-bit and 32-bit versions supported. Fix<BR>
'
computation of CGI_GMTOffset for offset=0 (GMT)<BR>
'
case. Add FieldPresent() routine for checkbox<BR>
'
handling. Clean up comments.<BR>
' 29-Oct-95 rbd Added PlusToSpace()
and Unescape() functions for<BR>
'
decoding query strings, etc.<BR>
' 16-Nov-95 rbd Add keep-alive
variable, file uploading description<BR>
'
in comments, and upload display.<BR>
' 20-Nov-95 rbd Fencepost error
in ParseFileValue()<BR>
' 23-Nov-95 rbd Remove On Error
Resume Next from error handler<BR>
' 03-Dec-95 rbd User-Agent is
now a variable, real HTTP header<BR>
'
Add Request-Range as http header as well.<BR>
'----------------------------------------------------------------------
<BR>
Option Explicit<BR>
'<BR>
' ==================<BR>
' Manifest Constants<BR>
' ==================<BR>
'<BR>
Const MAX_CMDARGS = 8 ' Max
# of command line args<BR>
Const ENUM_BUF_SIZE = 4096 ' Key enumeration buffer,
see GetProfile()<BR>
' These are the limits in the server<BR>
Const MAX_XHDR = 100 '
Max # of "extra" request headers<BR>
Const MAX_AccTYPE = 100 ' Max # of Accept:
types in request<BR>
Const MAX_FORM_TUPLES = 100 ' Max # form key=value pairs<BR>
Const MAX_HUGE_TUPLES = 16 ' Max # "huge"
form fields<BR>
Const MAX_FILE_TUPLES = 16 ' Max # of uploaded file
tuples<BR>
'<BR>
'<BR>
' =====<BR>
' Types<BR>
' =====<BR>
'<BR>
Type Tuple '
Used for Accept: and "extra" headers<BR>
key As String
' and for holding POST form key=value pairs<BR>
value As String<BR>
End Type<BR>
<BR>
Type FileTuple '
Used for form-based file uploads<BR>
key As String
' Form field name<BR>
file As String '
Local tempfile containing uploaded file<BR>
length As Long '
Length in bytes of uploaded file<BR>
type As String '
Content type of uploaded file<BR>
encoding As String '
Content-transfer encoding of uploaded file<BR>
name As String '
Original name of uploaded file<BR>
End Type<BR>
<BR>
Type HugeTuple '
Used for "huge" form fields<BR>
key As String
' Keyword (decoded)<BR>
offset As Long '
Byte offset into Content File of value<BR>
length As Long '
Length of value, bytes<BR>
End Type<BR>
'<BR>
'<BR>
' ================<BR>
' Global Constants<BR>
' ================<BR>
'<BR>
' ----------<BR>
' Error Codes<BR>
' ----------<BR>
'<BR>
Global Const ERR_ARGCOUNT = 32767<BR>
Global Const ERR_BAD_REQUEST = 32766 '
HTTP 400<BR>
Global Const ERR_UNAUTHORIZED = 32765
' HTTP 401<BR>
Global Const ERR_PAYMENT_REQUIRED = 32764 ' HTTP
402<BR>
Global Const ERR_FORBIDDEN = 32763 '
HTTP 403<BR>
Global Const ERR_NOT_FOUND = 32762 '
HTTP 404<BR>
Global Const ERR_INTERNAL_ERROR = 32761
' HTTP 500<BR>
Global Const ERR_NOT_IMPLEMENTED = 32760 '
HTTP 501<BR>
Global Const ERR_TOO_BUSY = 32758
' HTTP 503 (experimental)<BR>
Global Const ERR_NO_FIELD = 32757
' GetxxxField "no field"<BR>
Global Const CGI_ERR_START = 32757 '
Start of our errors<BR>
<BR>
' ====================<BR>
' CGI Global Variables<BR>
' ====================<BR>
'<BR>
' ----------------------<BR>
' Standard CGI variables<BR>
' ----------------------<BR>
'<BR>
Global CGI_ServerSoftware As String<BR>
Global CGI_ServerName As String<BR>
Global CGI_ServerPort As Integer<BR>
Global CGI_RequestProtocol As String<BR>
Global CGI_ServerAdmin As String<BR>
Global CGI_Version As String<BR>
Global CGI_RequestMethod As String<BR>
Global CGI_RequestKeepAlive As Integer<BR>
Global CGI_LogicalPath As String<BR>
Global CGI_PhysicalPath As String<BR>
Global CGI_ExecutablePath As String<BR>
Global CGI_QueryString As String<BR>
Global CGI_RequestRange As String<BR>
Global CGI_Referer As String<BR>
Global CGI_From As String<BR>
Global CGI_UserAgent As String<BR>
Global CGI_RemoteHost As String<BR>
Global CGI_RemoteAddr As String<BR>
Global CGI_AuthUser As String<BR>
Global CGI_AuthPass As String<BR>
Global CGI_AuthType As String<BR>
Global CGI_AuthRealm As String<BR>
Global CGI_ContentType As String<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -