?? cgi.cpp
字號(hào):
//---------------------------------------------------------------------------
#include <vcl\condefs.h>
#include <vcl\sysutils.hpp>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include "Unit1.h"
#pragma hdrstop
//---------------------------------------------------------------------------
USERES("CGI.res");
USEUNIT("Unit1.cpp");
//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
char *Method, *StrLen, *Buffer, *UserAgent, *Host;
char *FoundAmpersand, *WorkString, *QueryString;
long ContentLength;
Method = getenv("REQUEST_METHOD");
printf("Context-Type: text/html\n\n");
if (Method == NULL)
{
printf("This was not called from a web browser!\n");
return 0;
}
else if (strcmp(Method, "GET") == 0)
{
QueryString = getenv("QUERY_STRING");
if (QueryString)
{
Buffer = new char [strlen(QueryString) + 1];
strcpy(Buffer, QueryString);
}
else
{
printf("Could not process GET request");
return 0;
}
}
else if (strcmp(Method, "POST") == 0)
{
StrLen = getenv("CONTENT_LENGTH");
if (StrLen)
{
ContentLength = strtol(StrLen, NULL, 0);
if (ContentLength > 0)
{
Buffer = new char [ContentLength + 1];
fread((void *)Buffer, ContentLength, 1, stdin);
Buffer[ContentLength] = '\0';
}
else
{
printf("Content length was not specified!\n");
return 0;
}
}
else
{
printf("Content length was not specified\n");
return 0;
}
}
else
{
printf("Unrecognized method\n");
return 0;
}
printf("***Some HTTP Headers***\n");
UserAgent = getenv("HTTP_USER_AGENT");
if (!UserAgent)
printf("HTTP_USER_AGENT = Unknown\n");
else
printf("HTTP_USER_AGENT = %s\n", UserAgent);
Host = getenv("HTTP_HOST");
if (!Host)
printf("HTTP_HOST = Unknown\n");
else
printf("HTTP_HOST = %s\n", Host);
printf("\n***Information from form ***\n");
printf("Method: %s\n", Method);
Buffer = url2str(Buffer);
WorkString = Buffer;
FoundAmpersand = strchr(WorkString, '&');
while (FoundAmpersand)
{
FoundAmpersand[0] = '\0';
printf("%s\n", WorkString);
WorkString += (FoundAmpersand - WorkString + 1);
FoundAmpersand = strchr(WorkString, '&');
}
if (strlen(WorkString))
printf("%s\n", WorkString);
delete [] Buffer;
return 0;
}
//---------------------------------------------------------------------------
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -