#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <io.h>const char OUTFILE[] = "c:\\temp.txt";int main(int argc, char *argv[])
{
printf("Content-Type:text/html\n\n");
FILE *pFile;
pFile = fopen(OUTFILE, "w+b");
if(pFile == NULL)
{
printf("File open fail!\n");
return 0;
}; char *pMethod = getenv("REQUEST_METHOD");
if(pMethod == NULL)
{
printf("No Any Method!\n");
fclose(pFile);
return 0;
}
if(*pMethod == 0)
{
printf("No Any Method!\n");
fclose(pFile);
return 0;
} if(strcmp(pMethod, "GET") == 0)
{
printf("Get Ok!\n");
char *pString = getenv("QUERY_STRING");
if(pString != NULL)
fwrite(pString, 1, strlen(pString), pFile);
fclose(pFile);
return 1;
} if(strcmp(pMethod, "POST") == 0)
{
char *pCntLen = getenv("CONTENT_LENGTH");
if(!pCntLen)
{
fclose(pFile);
printf("Can't get Content_Length!\n");
return 0;
}
if(*pCntLen == 0)
{
fclose(pFile);
printf("Can't get Content_Length!\n");
return 0;
}
int StrLen = atoi(pCntLen);
if(StrLen <= 0)
{
fclose(pFile);
printf("String Length <= 0\n");
return 0;
}
/*char *pStr = new char[StrLen + 1];
int ReadNum = fread(pStr, 1, StrLen, stdin);
pStr[StrLen] = 0;
fwrite(pStr, 1, strlen(pStr), pFile);
delete pStr;*/
char *pStr;
pStr = new char[StrLen + 1];
*pStr = 0;
_setmode(_fileno(stdin), _O_BINARY);
fread(pStr, StrLen, 1, stdin);
fwrite(pStr, StrLen, 1, pFile);
_setmode(_fileno(stdin), _O_TEXT);
fclose(pFile);
delete pStr;
printf("%d", StrLen);
printf("%s", getenv("CONTENT_TYPE"));
printf("Post ok!\n");
return 1;
} fclose(pFile);
if(pMethod != NULL)
printf("%s\n", pMethod);
else
printf("pMethod is NULL!\n");
return 0;
}// 再贴一遍,你看明白了吗?
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <fcntl.h>
#include <io.h>const char OUTFILE[] = "c:\\temp.txt";int main(int argc, char *argv[])
{
printf("Content-Type:text/html\n\n");
FILE *pFile;
pFile = fopen(OUTFILE, "w+b");
if(pFile == NULL)
{
printf("File open fail!\n");
return 0;
}; char *pMethod = getenv("REQUEST_METHOD");
if(pMethod == NULL)
{
printf("No Any Method!\n");
fclose(pFile);
return 0;
}
if(*pMethod == 0)
{
printf("No Any Method!\n");
fclose(pFile);
return 0;
} if(strcmp(pMethod, "GET") == 0)
{
printf("Get Ok!\n");
char *pString = getenv("QUERY_STRING");
if(pString != NULL)
fwrite(pString, 1, strlen(pString), pFile);
fclose(pFile);
return 1;
} if(strcmp(pMethod, "POST") == 0)
{
char *pCntLen = getenv("CONTENT_LENGTH");
if(!pCntLen)
{
fclose(pFile);
printf("Can't get Content_Length!\n");
return 0;
}
if(*pCntLen == 0)
{
fclose(pFile);
printf("Can't get Content_Length!\n");
return 0;
}
int StrLen = atoi(pCntLen);
if(StrLen <= 0)
{
fclose(pFile);
printf("String Length <= 0\n");
return 0;
}
/*char *pStr = new char[StrLen + 1];
int ReadNum = fread(pStr, 1, StrLen, stdin);
pStr[StrLen] = 0;
fwrite(pStr, 1, strlen(pStr), pFile);
delete pStr;*/
char *pStr;
pStr = new char[StrLen + 1];
*pStr = 0;
_setmode(_fileno(stdin), _O_BINARY);
fread(pStr, StrLen, 1, stdin);
fwrite(pStr, StrLen, 1, pFile);
_setmode(_fileno(stdin), _O_TEXT);
fclose(pFile);
delete pStr;
printf("%d", StrLen);
printf("%s", getenv("CONTENT_TYPE"));
printf("Post ok!\n");
return 1;
} fclose(pFile);
if(pMethod != NULL)
printf("%s\n", pMethod);
else
printf("pMethod is NULL!\n");
return 0;
}// 再贴一遍,你看明白了吗?
<input TYPE = "text" name=name1>
</form>
cgi.exe xx yy zz
在网页中该怎么实现呢???
差不多了,呵呵