使用Cgicc获取表单数据

时间:2012-08-25 11:30:59

标签: c++ cgi form-data

char* fileContentLength;
int nContentLength;
fileContentLength = getenv("CONTENT_LENGTH");

if(fileContentLength == NULL)   
    return -1;      

nContentLength = atoi(fileContentLength);   

if(nContentLength == 0) 
    return -1;

data = (char*) malloc(nContentLength+1);

if(data == NULL)    
    return -1;

memset(data, 0, nContentLength+1);  
if(fread(data, 1, nContentLength, stdin) == 0)  
    return -1;

if(ferror(stdin))

这是用于将表单数据提供给字符数组的c ++ cgi代码。 执行此代码后,我得到了以下结果到变量“data”。

  

F0 = fname0&安培; 10 = lname0&安培; F1 = fname1&安培; L1 = lname1&安培; F2 = fname2&安培; L2 = lname2&安培; F3 =&安培; L3 =

现在我想使用cgicc在单个字符数组中检索上面的数据。但是使用cgicc我可以获得特定元素的价值。但我想检索单个字符数组中的所有元素值。我怎么能用cgicc做到这一点?

1 个答案:

答案 0 :(得分:0)

我知道这是一个非常晚的回复,但也许它可以帮助别人。

这可能与我遇到的问题有关。昨天我第一次开始使用C ++ Cgi脚本。我发现在使用POST方法提交数据时,代码中多次声明Cgicc(GET工作正常)导致“在抛出'std :: runtime_error'的实例后调用终止... ... what():I / O错误” 。它通过全局声明Cgicc来解决,因此在代码中只有一次。